Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
using variable with .Activate
Hi
I'm trying to use a variable in the following code but i get an error. Subscript out of range I am runing a For/Next loop and need to change the file name for every loop Dim MyString AS String Dim MyFileName AS String MyString = C:\path\filename MyFileName = somefilename Windows(MyString).Activate Sheets(MyFileNAme).Select Any suggestion on how to do this correctly. Many thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
using variable with .Activate
Enclose the string in double-quotes:
MyString = "C:\path\filename" The Sheets().Activate selects a tab not a workbook -- Gary's Student "Super Slueth" wrote: Hi I'm trying to use a variable in the following code but i get an error. Subscript out of range I am runing a For/Next loop and need to change the file name for every loop Dim MyString AS String Dim MyFileName AS String MyString = C:\path\filename MyFileName = somefilename Windows(MyString).Activate Sheets(MyFileNAme).Select Any suggestion on how to do this correctly. Many thanks |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
using variable with .Activate
Use the filename only, not path and filename.
-- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "Super Slueth" wrote in message ... Hi I'm trying to use a variable in the following code but i get an error. Subscript out of range I am runing a For/Next loop and need to change the file name for every loop Dim MyString AS String Dim MyFileName AS String MyString = C:\path\filename MyFileName = somefilename Windows(MyString).Activate Sheets(MyFileNAme).Select Any suggestion on how to do this correctly. Many thanks |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
using variable with .Activate
Dim MyString AS String
Dim MySheetName AS String MyString = "filename.xls" ' no path MySheetName = "sheet1" ' as an example Windows(MyString).Activate Sheets(MyFileNAme).Select -- Regards, Tom Ogilvy "Gary''s Student" wrote in message ... Enclose the string in double-quotes: MyString = "C:\path\filename" The Sheets().Activate selects a tab not a workbook -- Gary's Student "Super Slueth" wrote: Hi I'm trying to use a variable in the following code but i get an error. Subscript out of range I am runing a For/Next loop and need to change the file name for every loop Dim MyString AS String Dim MyFileName AS String MyString = C:\path\filename MyFileName = somefilename Windows(MyString).Activate Sheets(MyFileNAme).Select Any suggestion on how to do this correctly. Many thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Workbook.Activate / Window.Activate problem | Excel Programming | |||
Can a variable be used in a Worksheet().Activate method | Excel Programming | |||
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? | Excel Worksheet Functions | |||
Reference to a variable in windows(???).Activate | Excel Programming | |||
How to activate a file when the filename is represented by a string variable | Excel Programming |