activating a workbook

  • Thread starter VB Script for Excel
  • Start date
V

VB Script for Excel

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 : )
 
V

VB Script for Excel

Gary
It still does not work. Gives me a Run-Time Error 9 message: Subscript
out of range.
Thanks
 
G

Gary Keramidas

if it's already loaded, try this. you may not have the file extension in A1

Windows(fileA & ".xls").Activate
 
V

VB Script for Excel

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).
:)
 
V

VB Script for Excel

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
 
V

VB Script for Excel

Again gives me same Run Time Error '9': Subscript out of range. Makes
the line Windows(fileA & ".xls").Activate as yellow.

Thnx
 
G

Gary Keramidas

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
 
G

Gary Keramidas

you have & ".xls" already in A1, i didn't know until you just posted the
formula, so this wouldn't work.
 
V

VB Script for Excel

IT WORKS GARY!!!!
thank you so much and thanks a millionsss.
i really appreciate your help

Dhaval
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top