ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB Script for Excel Revised Question (https://www.excelbanter.com/excel-programming/356762-vbulletin-script-excel-revised-question.html)

VB Script for Excel

VB Script for Excel Revised Question
 
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

However this does not seem to work. It gives me an error message
"Run-Time Error '9': Subscript Out of Range" and stops at the third
line (windows("fileA").Activate).

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


Nicholas B[_2_]

VB Script for Excel Revised Question
 
Try

WorkBooks.Open (FileA)

in place of

Windows("FileA").Activate

No quotes around (FileA)

Nick

"VB Script for Excel" wrote:

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

However this does not seem to work. It gives me an error message
"Run-Time Error '9': Subscript Out of Range" and stops at the third
line (windows("fileA").Activate).

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




All times are GMT +1. The time now is 03:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com