简体   繁体   English

通过访问VBA浏览和编辑Excel文件

[英]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”. 我是vba的新手。...要求提供以下内容的指导:我想创建一个Access vba工具,其目的是仅浏览多个excel文件,并通过在()上添加新行来更新/编辑所有选定的excel文件。如工作表1)的第一行,文字为“ ABC”。 And, then it should save and close all the excel files. 然后,它应该保存并关闭所有excel文件。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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