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 a variable file name

Being a newbie, I apologize if this appears to be a trivial problem. I
tried looking at past postings but they don't seem to help much.

I am simply trying to copy and paste some stuff from one file to
another and my macro looks like:

Windows("C1.xls").Activate
Range("G12").Select
Selection.Copy
Windows("Standard Input Template.xls").Activate
Range("G12").Select
ActiveSheet.Paste

where C1.xls is the file I'm copying from and the macro belongs to the
file "Standard Input Template".

However I may need to copy from other files and a sheet in it with the
same name as the file name.

So I've set up by picking the file name and the sheet name from a cell
:
***********
Dim Sname As String
Dim IFname As String

'
'Enter Basic Information
Application.ScreenUpdating = False

Sname = Range("E11").Value
IFname = Sname & ".xls!" & Sname


Windows(" & IFname & ").Activate
Range("E12:E13").Select
Selection.Copy
Windows("Standard Input Template.xls").Activate
Range("E12").Select
ActiveSheet.Paste
***********
This does not work :((

Please help!!!

Thanks in advance
Utkarsh
  #2   Report Post  
Posted to microsoft.public.excel.programming
rog rog is offline
external usenet poster
 
Posts: 39
Default Using a variable file name

Try

Windows(IFname).Activate

instead of

Windows(" & IFname & ").Activate

Rgds

Rog



-----Original Message-----
Being a newbie, I apologize if this appears to be a

trivial problem. I
tried looking at past postings but they don't seem to

help much.

I am simply trying to copy and paste some stuff from one

file to
another and my macro looks like:

Windows("C1.xls").Activate
Range("G12").Select
Selection.Copy
Windows("Standard Input Template.xls").Activate
Range("G12").Select
ActiveSheet.Paste

where C1.xls is the file I'm copying from and the macro

belongs to the
file "Standard Input Template".

However I may need to copy from other files and a sheet

in it with the
same name as the file name.

So I've set up by picking the file name and the sheet

name from a cell
:
***********
Dim Sname As String
Dim IFname As String

'
'Enter Basic Information
Application.ScreenUpdating = False

Sname = Range("E11").Value
IFname = Sname & ".xls!" & Sname


Windows(" & IFname & ").Activate
Range("E12:E13").Select
Selection.Copy
Windows("Standard Input Template.xls").Activate
Range("E12").Select
ActiveSheet.Paste
***********
This does not work :((

Please help!!!

Thanks in advance
Utkarsh
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using a variable file name

Thanks Rog for the help.

However when I run the code as suggested it gives me an error:

Runtime error '9': Subscript out of range.

What could be happening?

Thanks
Utkarsh



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using a variable file name

It worked!!! A typo on my part was creating the problem.
Thank you so much, Rog!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Variable File Name Tigerxxx Excel Discussion (Misc queries) 4 March 8th 09 05:24 AM
calling a value from another file using a variable in the file nam DA_Potts[_2_] Excel Worksheet Functions 3 December 3rd 07 12:25 AM
calling a value from another file using a variable in the file nam DA_Potts[_2_] Excel Discussion (Misc queries) 4 December 2nd 07 11:09 PM
Variable File Name [email protected] Excel Worksheet Functions 1 June 18th 06 10:36 AM
Variable File Name Trevor[_4_] Excel Programming 3 June 18th 04 07:10 PM


All times are GMT +1. The time now is 07:28 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"