Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
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
Workbook.Activate / Window.Activate problem Tim[_44_] Excel Programming 3 February 3rd 06 11:38 PM
Can a variable be used in a Worksheet().Activate method Brad Sumner Excel Programming 3 September 12th 05 07:09 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Reference to a variable in windows(???).Activate John Baker Excel Programming 7 July 13th 04 02:04 PM
How to activate a file when the filename is represented by a string variable news.sintef.no Excel Programming 4 February 6th 04 02:17 PM


All times are GMT +1. The time now is 09:58 PM.

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

About Us

"It's about Microsoft Excel"