VBA Code for next open application

Microsoft Office 2003 basic edition
November 25, 2009 at 07:02:39
Specs: Windows XP

I need to switch between 2 open excel worksheets and copy data from one to another. I cannot use the file names to say which one I want to switch into as one of the files is a template that gets saved under a different name beforte thsi procedure. So the fiel name cannot be hardcoded in teh VBA code. The Old Excell macro had a nice function like


Is there an equivalent in eth VBA for this? if not how can I achieve the same end result?

Thanks for any help.


See More: VBA Code for next open application

Report •

November 25, 2009 at 07:40:52
Here is a way to swap between two workbooks. It is not very elegant, and hopefully someone else will have a better way of doing this!

This method uses the Workbooks collection, and iterates through the collection, activating the one that does not have the same name as the current active workbook (and ignoring PERSONAL.XLS).

Private Sub chWB()
Dim rngWB As Workbook
For Each rngWB In Workbooks()
    If Not (rngWB.Name = ActiveWorkbook.Name Or rngWB.Name = "PERSONAL.XLS") Then
        Exit For
    End If
End Sub



Report •
Related Solutions

Ask Question