To the poster above, if you're having trouble with the macro reference (if you are only doing one file) in Excel (I don't know about other products - didn't try) but you can just add this line after your initial open:
ActiveWindow.ActivateNext
because excel opens new windows to open files in macros, its still looking at the window with your initial file. This will force it to open the next window.
Now, I'm having a similar problem to him, but somewhat more complicated. Mine is running a loop to open all files in a particular folder, print them and close them. I have the macro working - to some degree. here is my code (this is excel):
- Sub RMPProducer()
-
-
OldPath = "S:\RMBS_Performance_Analytics\Analysis\1 Staging Folder For Monthly Model Templates\2007\200704\VV\Deals"
-
Dim t As Workbook
-
Dim s As String
-
Dim a As Window
-
-
With Application.FileSearch
-
.NewSearch
-
.LookIn = OldPath
-
.SearchSubFolders = False
-
.Filename = "*.xls"
-
.MatchTextExactly = True
-
If .Execute() > 0 Then
-
For i = 1 To .FoundFiles.Count
-
s = .FoundFiles(i)
-
Workbooks.Open (s)
-
Set t = Workbooks(i)
-
t.Activate
-
ActiveWindow.ActivateNext
-
ActiveWorkbook.Sheets("Summary").Select
-
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
-
ActiveWorkbook.Sheets("Collateral Graphs").Select
-
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
-
ActiveWorkbook.Sheets("CLASS CE GRAPH").Select
-
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
-
ActiveWorkbook.Sheets("XS AND OC TABLE").Select
-
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
-
Next i
-
Else
-
MsgBox "There were no files found."
-
End If
-
End With
-
End Sub
I have 2 problems. First problem is that I am trying to add a function to make the window close once its finished printing. This actually works - but it limits my loop iterations from i = 1 to 2 (so it only runs 2 times and I'm not exactly sure why). If I don't include the statement - this can run for up to 7 - 8 times (these are very large files) then excel runs out of memory. Unfortunately, i can't set the loop to run from i = anything other than one.
So What I would prefer is to be able to actually activate the ActiveWindow.close command - because this way I can run the entire loop. But I'm not sure how to. I tried window referencing, I tried adding a new active Window so when the file opens, its opening in the active window already, but nothing works.
Preferably, I need to be able to reference both windows, as my next macro will involve referencing 2 windows (one static - always open) and the other the loop above.
Anyone have any ideas/ All help is appreciated.