简体   繁体   中英

Browse and edit excel files via access vba

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

I found the answer, below is code for further reference.

Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
Dim MySheetPath As String
Dim fDialog As FileDialog
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
MySheetPath = GetFileName
Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(MySheetPath)
Xl.Visible = True
XlBook.Windows(1).Visible = True
Set XlSheet = XlBook.Worksheets(1)
Dim varInquiryID As Long
Dim varCentreFooter As String
Dim sHeader As String
varCentreFooter = " ABC "
XlSheet.PageSetup.CenterFooter = varCentreFooter

ActiveWorkbook.Save
ActiveWorkbook.Close

Next
End If
End With

Set Xl = Nothing
Set XlBook = Nothing
Set XlSheet = Nothing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM