Browse and edit excel files via access vba

Rakesh935

Registered User.
Local time
Tomorrow, 04:44
Joined
Oct 14, 2012
Messages
71
Hi there,
I am new to access vba….requesting to please guide for the below mentioned:
I want to create an access vba tool and its purpose is to browse multiple excel files only and update/edit all selected excel files by adding a new row on (as in the first row of sheet1) with a text as “ABC”. And, then it should save and close all the excel files.
Thank you
Rakesh
 
I wrote the below mentioned code but unfortunately while executing only the first file selected is getting updated but not the rest of the others…..Please guide…
Private Sub Command0_Click()
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
Dim MySheetPath As String


Dim fDialog As FileDialog
' Set up the File Dialog. '
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

Dim varFile As Variant

With fDialog
.AllowMultiSelect = True
.Title = "Select File Location to Export XLSx :"
.InitialFileName = ""

If .Show = True Then
For Each varFile In .SelectedItems
GetFileName = varFile
Next
End If
End With

MySheetPath = GetFileName

Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(MySheetPath)

Xl.Visible = True
XlBook.Windows(1).Visible = True

Set XlSheet = XlBook.Worksheets(1)

XlSheet.Rows(1).EntireRow.Insert
XlSheet.Range("A1") = "ABC"
Xl.ActiveWorkbook.Save
Xl.ActiveWorkbook.Close
Xl.Quit
Set Xl = Nothing
Set XlBook = Nothing
Set XlSheet = Nothing
End Sub
 

Users who are viewing this thread

Back
Top Bottom