我想打開多個Excel文件(97,2003,2007,2010 ..等),編輯它們並保存它們。如果我打開Visual Basic編輯器(Alt + F11)並要求在開始時啓用宏,但是如果我的VB編輯器關閉,它將打開文件並停止保存第一個文件。VBA:打開,編輯,保存...在VB編輯器打開時工作,而不是在關閉時工作?
我使用這個命令:
Set OpenWB = Workbooks.Open(FilePath)
OpenWB
哪裏被聲明爲Workbook
對象。這工作正常,即使打開宏文件沒有被問到?但是,當我打開VisualBasic編輯器(Alt-F11),我有那個
然後我編輯數據。然後保存使用此命令:
' Save File
OpenWB.Save
該代碼嘗試保存,但然後在那裏休息。我試圖啓用&禁用Application.DisplayAlerts
(True/False)。
問題是,我無法打開VB編輯器運行它,因爲我需要禁用宏警告,因爲我有1000多個文件。然而,沒有它打開代碼doens't通過保存代碼行。代碼的一部分的
實施例:
'Path
FilePath = FL.Cells(FileListCount, 1).Value
' Begin first loop
While FilePath <> ""
' Alerts?
Application.DisplayAlerts = False
' Open File
Set OpenWB = Workbooks.Open(FilePath)
' Alerts
Application.DisplayAlerts = True
' Enter Replacement Loop
ReplacementCount = 1
ID = Ctrl.Cells(ReplacementCount + 11, 2).Value
While ID <> ""
OpenWB.Sheets(Ctrl.Cells(ReplacementCount + 11, 4).Value).Range(Ctrl.Cells(ReplacementCount + 11, 5).Value).Value = Ctrl.Cells(ReplacementCount + 11, 3).Value
ReplacementCount = ReplacementCount + 1
ID = Ctrl.Cells(ReplacementCount + 11, 2).Value
Wend
' Save File
OpenWB.Save
' Close file
OpenWB.Close
' status
FL.Cells(FileListCount, 2).Value = "***** UPDATED *****"
' Increment counter
FileListCount = FileListCount + 1
' Call new path
FilePath = FL.Cells(FileListCount, 1).Value
Wend
您是否看到錯誤訊息?如果是,那是什麼? –
這就是事情 - VBeditor打開:安全通知問題?, - VBeditor關閉:保存第一個文件後停止沒有錯誤。 – CromeX