【发布时间】:2016-06-21 15:28:15
【问题描述】:
如果文件名与命名约定接近,下面的代码将循环打开打开的 excel 文件,然后运行 if 语句中的代码,以便以后保存文件
此代码在 excel 2003 中有效,但在 excel 2010 中无效,查看代码的每个部分,myWindow.Caption 似乎只获得 1 个文件名,而不是应该有的 5 个。我错过了什么让它循环遍历 2010 年的所有文件?
仅供参考 - For 循环有多个实例,但由于它们都是相同的代码,我没有在这里粘贴。如果你想要它,请告诉我,但它足够相似
Sub File_Saver()
Dim iFileCount As Integer
Dim myWindow As Window
Dim r As Integer
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
For Each myWindow In Application.Windows
If LCase(myWindow.Caption) Like LCase("CHL?ISS*") Then
iFileCount = 1
r = 21
myWindow.Activate
'Set Column
c = B
GoTo Continue
Exit For
End If
Next myWindow
【问题讨论】:
-
要正常工作,您需要运行应用程序的多个实例...只需打开所有文件,通常会将其“合并”到 1 个窗口(带有实际活动工作簿的标题).. . 然后你应该为工作簿中的每个项目运行(以获取所有打开的工作簿名称)
标签: vba excel excel-2010