簡體   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