Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Refer to Unknown File Name

I need to switch between 2 open files in a macro. I know the name of one
file but not the other. What code can I use to activate the workbook that I
don't know the name of?
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Refer to Unknown File Name

Maybe

Activewindow.ActivateNext

but it wouldn't be my first choice as it depends on there being only two
workbooks open.


Can you use the macros in the first workbook to open the second during
execution? Since you don't know the file name, I assume the user has to open
the second book.

Sub test()
Dim wkbTest As Workbook
Dim varFName As Variant

varFName = Application.GetOpenFilename
If varFName = False Then End

Set wkbTest = Workbooks.Open(Filename:=varFName)

End Sub


Then you can use the object variable, wkbTest (change variable name if you
like) to refer to the second book.

wkbTest.Worksheets("Sheet1").Range("A1").Value = 5




"Lynn" wrote:

I need to switch between 2 open files in a macro. I know the name of one
file but not the other. What code can I use to activate the workbook that I
don't know the name of?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open unknown file name Jan Excel Programming 4 March 9th 06 02:51 AM
Paste sheet to new file with unknown file name - VBA [email protected] Excel Programming 2 October 5th 05 05:41 PM
Linked file in same folder but unknown path Christy Excel Programming 6 October 4th 05 06:30 PM
refer to unknown window name Ciara[_2_] Excel Programming 4 June 16th 05 04:59 PM
How to Activate unknown file name Ashley[_3_] Excel Programming 1 June 4th 04 06:41 PM


All times are GMT +1. The time now is 07:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"