Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro Switch between Workbooks

Status
Not open for further replies.

rnordquest

New member
Jul 17, 2003
148
Macro in one xls file opens file to process using Application.FindFile. It extracts data and outputs it in a macro opened txt file. How do I switch between files? I obviously know the name of the file the macro is in and the output file but I can pick any file to process with the .Find. How do I pass the macro opened filename to the macro so I can "Workbooks("???.xls").Activate"?

The user might have already opened other workbooks so "Workbooks("BOOK?").Activate" won't work since I don't know what number the latest one used.
 
Replies continue below

Recommended for you

No need to answer orig ?. I already found a way around this by doing save as. I'd still rather know how to access the file name.

Roger
 
You can see the name of all open workbooks by:
Code:
For each W in Application.Workbooks
    Debug.Print W.Name, W.FullName
Next W
Maybe this helps you along a bit

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Here's what I did:

Application.FindFile
On Error Resume Next
Workbooks("Process.xls").Close SaveChanges:=False
Kill "Process.xls"
On Error GoTo 0
ActiveWorkbook.SaveAs FileName:="Process.xls"

I closed a file name if open, deleted it and then saved as a name I've chosen. Now I'm sure of the name. Your's would show me all the names but it wouldn't tell me which one the user just opened.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor