下面的代码通过打开的excel文件循环,如果文件名是命名约定接近的话,它将运行if语句中的代码,以便文件可以稍后保存VBA Excel - .Window无法识别打开的Excel窗口
此代码适用于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个窗口(带有实际活动工作簿的标题)...您应该为每个项目运行然后在工作簿中(获取所有打开的工作簿名称) –