1

我是访问 vba 的新手……请求指导以下内容:我想创建一个访问 vba 工具,其目的是仅浏览多个 excel 文件并通过在 (如 sheet1) 的第一行,文本为“ABC”。然后,它应该保存并关闭所有的 excel 文件。谢谢

4

1 回答 1

0

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

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
于 2012-11-25T18:12:15.520 回答