VBA Excel – .Window不能识别打开的Excel窗口

下面的代码通过打开的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 

对于多个Excel实例来看看这个答案: VBA可以跨越Excel的实例吗?

这适用于Excel的一个实例:

 Dim workBooks as Workbooks Dim book As Workbook Set workBooks = Application.Workbooks For Each book In workbooks If LCase(book.Name) Like LCase("CHL?ISS*") Then iFileCount = 1 r = 21 book.Activate c = B ' Not sure where the Continue: statement is GoTo Continue Exit For End If Next