Excel VBA:打开、编辑、保存。。。VB编辑器打开时工作,而不是关闭时工作?
我试图打开多个excel文件(97200320072010…等),编辑并保存它们。如果打开Visual Basic编辑器(Alt+F11)并要求在开始时启用宏,则宏可以工作,但如果关闭VB编辑器,则会打开文件并在保存第一个文件时停止 我使用此命令:Excel VBA:打开、编辑、保存。。。VB编辑器打开时工作,而不是关闭时工作?,excel,save,vba,Excel,Save,Vba,我试图打开多个excel文件(97200320072010…等),编辑并保存它们。如果打开Visual Basic编辑器(Alt+F11)并要求在开始时启用宏,则宏可以工作,但如果关闭VB编辑器,则会打开文件并在保存第一个文件时停止 我使用此命令: Set OpenWB = Workbooks.Open(FilePath) ' Save File OpenWB.Save 其中,OpenWB被声明为Workbook对象。这很好,甚至可以在没有被要求的情况下打开宏文件?但是,当我打开Visual
Set OpenWB = Workbooks.Open(FilePath)
' Save File
OpenWB.Save
其中,OpenWB
被声明为Workbook
对象。这很好,甚至可以在没有被要求的情况下打开宏文件?但是,当我打开Visual Basic编辑器(Alt-F11)时,我发现
然后我编辑数据。然后使用以下命令保存:
Set OpenWB = Workbooks.Open(FilePath)
' Save File
OpenWB.Save
代码试图保存,但在那里就中断了。我已尝试启用和禁用应用程序。DisplayAlerts
(真/假)
问题是,我不能在VB编辑器打开的情况下运行它,因为我需要禁用宏警告,因为我有1000多个文件。但是,如果没有打开,代码将无法通过保存代码行
代码的一部分示例:
'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
路径
FilePath=FL.Cells(FileListCount,1).Value
'开始第一个循环
而文件路径为“”
“警报?
Application.DisplayAlerts=False
'打开文件
设置OpenWB=Workbooks.Open(文件路径)
“警报
Application.DisplayAlerts=True
'进入替换循环
替换计数=1
ID=Ctrl.Cells(ReplacementCount+11,2).Value
而ID为“”
OpenWB.Sheets(Ctrl.Cells(ReplacementCount+11,4).Value).Range(Ctrl.Cells(ReplacementCount+11,5).Value=Ctrl.Cells(ReplacementCount+11,3).Value
ReplacementCount=ReplacementCount+1
ID=Ctrl.Cells(ReplacementCount+11,2).Value
温德
'保存文件
OpenWB.Save
'关闭文件
打开wb,关闭
"地位",
FL.Cells(FileListCount,2).Value=“*******已更新*****”
'增量计数器
FileListCount=FileListCount+1
'调用新路径
FilePath=FL.Cells(FileListCount,1).Value
温德
这是未经测试的
您是否已经尝试过:
Workbooks.Open(FilePath)
Set OpenWB = ActiveWorkbook.ActiveSheet
'ur goes here code
OpenWB.Activate
ActiveWorkbook.Close SaveChanges:=True
这将消除保存行和关闭行。是否看到错误消息?如果是,是什么?这就是问题所在-VBeditor打开:安全通知问题?,-VBeditor关闭:保存第一个文件后停止无错误。