ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting Workbooks (https://www.excelbanter.com/excel-programming/319170-selecting-workbooks.html)

Darren

Selecting Workbooks
 
After getting the user to select the file to open by:
fName = Application.GetOpenFilename
Workbooks.Open Filename:=fName
Any idea how can i refer to this workbook again later on in my code?

JulieD

Selecting Workbooks
 
Hi Darren

as long as you don't redefine fName

Workbooks(fName).Activate
or
Workbooks(fName).Sheets("Sheet1").Select
etc

Cheers
JulieD


"Darren" wrote in message
...
After getting the user to select the file to open by:
fName = Application.GetOpenFilename
Workbooks.Open Filename:=fName
Any idea how can i refer to this workbook again later on in my code?




Tim Williams

Selecting Workbooks
 
dim wb as workbook

fName = Application.GetOpenFilename
set wb=workbooks.open(fName)


Tim

"Darren" wrote in message
...
After getting the user to select the file to open by:
fName = Application.GetOpenFilename
Workbooks.Open Filename:=fName
Any idea how can i refer to this workbook again later on in my code?




Darren

Selecting Workbooks
 
Thanks guys

Dave Peterson[_5_]

Selecting Workbooks
 
Watch out.

fName will include the drive\path when it comes back from .getopenfilename.

You could strip the drive\path out of the string, or use a variable like Tim
suggested.



JulieD wrote:

Hi Darren

as long as you don't redefine fName

Workbooks(fName).Activate
or
Workbooks(fName).Sheets("Sheet1").Select
etc

Cheers
JulieD

"Darren" wrote in message
...
After getting the user to select the file to open by:
fName = Application.GetOpenFilename
Workbooks.Open Filename:=fName
Any idea how can i refer to this workbook again later on in my code?


--

Dave Peterson


All times are GMT +1. The time now is 02:14 PM.

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