Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

activating a workbook

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
VB Script for Excel - 22 Mar 2006 07:36 GMT
I need to activate a workbook through a cell reference. the workook
name is stored in cell A1 as "pnlreport_060321.xls". This name
automatically changes daily based on the date. This is how I wrote the
code to activate the workbook:

Sub import()

Dim fileA As String
fileA = Range("A1").Value
windows("fileA").Activate

End Sub

Please HELP. How would I activate a workbook which is already open. I
cannot use the file name in the code because the name changes every
day.

Thanks : )
Gary Keramidas - 22 Mar 2006 07:53 GMT
if it's already open, just delete the quotes

Windows(fileA).Activate

Signature

Gary

>I need to activate a workbook through a cell reference. the workook
> name is stored in cell A1 as "pnlreport_060321.xls". This name
[quoted text clipped - 14 lines]
>
> Thanks : )
VB Script for Excel - 22 Mar 2006 07:58 GMT
Gary
It still does not work. Gives me a Run-Time Error 9 message: Subscript
out of range.
Thanks
Gary Keramidas - 22 Mar 2006 08:13 GMT
also, is the workbook already open, or do you need code to open it, too?

Signature

Gary

> Gary
> It still does not work. Gives me a Run-Time Error 9 message: Subscript
> out of range.
> Thanks
VB Script for Excel - 22 Mar 2006 08:20 GMT
The workbook is already open. Need to activate that open workbook.
filename to open that workbook is located in cell A1 of current
workbook (the workbook in which I am writing the macros).
:)
Gary Keramidas - 22 Mar 2006 08:19 GMT
if it's already loaded, try this. you may not have the file extension in A1

Windows(fileA & ".xls").Activate

Signature

Gary

> Gary
> It still does not work. Gives me a Run-Time Error 9 message: Subscript
> out of range.
> Thanks
VB Script for Excel - 22 Mar 2006 08:29 GMT
Again gives me same Run Time Error '9':  Subscript out of range. Makes
the line Windows(fileA & ".xls").Activate as yellow.

Thnx
Gary Keramidas - 22 Mar 2006 08:36 GMT
you have & ".xls" already in A1, i didn't know until you just posted the
formula, so this wouldn't work.

Signature

Gary

> Again gives me same Run Time Error '9':  Subscript out of range. Makes
> the line Windows(fileA & ".xls").Activate as yellow.
>
> Thnx
Gary Keramidas - 22 Mar 2006 08:12 GMT
what, exactly, is in A1

Signature

Gary

>I need to activate a workbook through a cell reference. the workook
> name is stored in cell A1 as "pnlreport_060321.xls". This name
[quoted text clipped - 14 lines]
>
> Thanks : )
VB Script for Excel - 22 Mar 2006 08:23 GMT
A1 in the current workbook gives me the file name that changes everyday
due to date.
A1 shows:
="pnlreport_"& TEXT(now(),"yymmdd")& ".xls"
this will produce: pnlreport_060321.xls if today's date is 21st March
2006.

I need to activate this file, which is already open through VB. But it
gives me a run time error in above code.

Thanks
Gary Keramidas - 22 Mar 2006 08:34 GMT
i put your formula in A1 and this worked for me
Windows(fileA).Activate

maybe you should qualify the range with the sheet name, since i don't know what
the active sheet is

fileA =
workbooks("YourWorkbookName").worksheets("YourSheetName").Range("A1").Value

Signature

Gary

> A1 in the current workbook gives me the file name that changes everyday
> due to date.
[quoted text clipped - 7 lines]
>
> Thanks
VB Script for Excel - 22 Mar 2006 08:45 GMT
IT WORKS GARY!!!!
thank you so much and thanks a millionsss.
i really appreciate your help

Dhaval
Gary Keramidas - 22 Mar 2006 08:55 GMT
you're welcome

Signature

Gary

> IT WORKS GARY!!!!
> thank you so much and thanks a millionsss.
> i really appreciate your help
>
> Dhaval
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.