繁体   English   中英

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

[英]Browse and edit excel files via access vba

我是vba的新手。...要求提供以下内容的指导:我想创建一个Access vba工具,其目的是仅浏览多个excel文件,并通过在()上添加新行来更新/编辑所有选定的excel文件。如工作表1)的第一行,文字为“ ABC”。 然后,它应该保存并关闭所有excel文件。 谢谢

我找到了答案,下面是代码以供进一步参考。

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