Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
bw bw is offline
external usenet poster
 
Posts: 74
Default Variable Filename/Worksheet/Workbook

I'm using the following code to get the filename I want to open:

my2ndFileName = Application.GetOpenFilename("All Files (*.*), *.*")
where the actual filename is "C:\Downloads\LAS6014"

and I use the following to open the file:
Workbooks.OpenText Filename:=my2ndFileName,...

and because I don't now how to use the variable filename in the following, I hard code it
as follows:
Windows("LAS6014").Activate

So the question is: how do I activate the worksheet (or is it a workbook) for the variable
filename?

Thanks,
Bernie


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Variable Filename/Worksheet/Workbook

Try

my2ndfilename = Application.GetOpenFilename("All Files (*.*), *.*")
If my2ndfilename < "" Then
Workbooks.Open my2ndfilename
Workbooks(Workbooks.Count).Activate
End If

The newly loaded workbook is always going to be last in the list so by using
workbooks.count we're always going to activate the newly opened book.

You are refering to workbooks here not worksheets. A workbook is a
collection of worksheets (and other things). Trouble with getting the
filename is as you've found it is a fully qualified name with a path and
filename extension etc. It's just the filename iteself (without extension)
which the name given to the workbook.

Remember to also check to see if the user didn't hit cancel. That's what
the < "" check is for.


--

Regards,


Bill Lunney
www.billlunney.com

"bw" wrote in message
...
I'm using the following code to get the filename I want to open:

my2ndFileName = Application.GetOpenFilename("All Files (*.*), *.*")
where the actual filename is "C:\Downloads\LAS6014"

and I use the following to open the file:
Workbooks.OpenText Filename:=my2ndFileName,...

and because I don't now how to use the variable filename in the following,

I hard code it
as follows:
Windows("LAS6014").Activate

So the question is: how do I activate the worksheet (or is it a workbook)

for the variable
filename?

Thanks,
Bernie




  #3   Report Post  
Posted to microsoft.public.excel.programming
bw bw is offline
external usenet poster
 
Posts: 74
Default Variable Filename/Worksheet/Workbook

Thanks Bill,

This works fine now. I appreciate the explanation regarding workbooks/worksheets.
And while I had come across the "Count" portion previously, I hadn't realized that it was a
value that was the "Last" workbook, and that Count-1 was the previous. A little slow I
guess, but I'm getting there.

Again, thanks much...
Bernie


On Sat, 19 Jul 2003 18:59:10 +0100, "Bill Lunney"
wrote:
Try

my2ndfilename = Application.GetOpenFilename("All Files (*.*), *.*")
If my2ndfilename < "" Then
Workbooks.Open my2ndfilename
Workbooks(Workbooks.Count).Activate
End If

The newly loaded workbook is always going to be last in the list so by using
workbooks.count we're always going to activate the newly opened book.

You are refering to workbooks here not worksheets. A workbook is a
collection of worksheets (and other things). Trouble with getting the
filename is as you've found it is a fully qualified name with a path and
filename extension etc. It's just the filename iteself (without extension)
which the name given to the workbook.

Remember to also check to see if the user didn't hit cancel. That's what
the < "" check is for.


--

Regards,


Bill Lunney
www.billlunney.com

"bw" wrote in message
...
I'm using the following code to get the filename I want to open:

my2ndFileName = Application.GetOpenFilename("All Files (*.*), *.*")
where the actual filename is "C:\Downloads\LAS6014"

and I use the following to open the file:
Workbooks.OpenText Filename:=my2ndFileName,...

and because I don't now how to use the variable filename in the following,

I hard code it
as follows:
Windows("LAS6014").Activate

So the question is: how do I activate the worksheet (or is it a workbook)

for the variable
filename?

Thanks,
Bernie







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
How do I make the filename in a link variable based on a cell valu Bekki May New Users to Excel 4 February 4th 09 08:48 AM
Nested String Filename Variable ed9213 Excel Worksheet Functions 9 February 12th 07 02:27 AM
Variable in a filename reference in Excel 2000 pdabill Excel Discussion (Misc queries) 1 August 24th 06 11:08 PM
Entering a filename as a variable into cell similar as for footer Doug Excel Discussion (Misc queries) 3 May 17th 06 04:39 AM
Put Filename Variable in Macro David Excel Discussion (Misc queries) 4 December 27th 05 06:27 PM


All times are GMT +1. The time now is 07:30 AM.

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"