Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default set a workbook variable

You can do the assignment when you open the workbook. That makes it nice if
there are no visible windows (a hidden workbook or an addin).

Sub Macro1()
Dim s As String
Dim wb As Workbook
s = "C:\test\beta.xls"
set wb = Workbooks.Open(Filename:=s)
MsgBox wb.Name & vblf & wb.path & vblf & wb.fullname
End Sub

But the workbook does have to be open to be part of the workbooks collection.

dstiefe wrote:

so you have to first open the workbook to do it?

"Gary''s Student" wrote:

I would set the path/filename to a string and then set the workbook name
after it is opened:

Sub Macro1()
Dim s As String
Dim wb As Workbook
s = "C:\test\beta.xls"
Workbooks.Open Filename:=s
Set wb = ActiveWorkbook
MsgBox (wb.Name)
MsgBox (wb.Path)
End Sub
--
Gary''s Student - gsnu200902


"dstiefe" wrote:

I would like to set my variable "wb" to a workbook object

so something like this

dim wb as workbook

set wb = ????

I would like to set the variable "wb" to a workbook that is not open and in
a different folder...can i do that?


--

Dave Peterson
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
Pass Workbook Name Into Another Workbook As A Variable Minitman Excel Programming 4 September 11th 08 06:48 AM
Can a workbook variable be set by clicking the workbook? Kobayashi[_47_] Excel Programming 0 October 29th 04 10:23 AM
Can a workbook variable be set by clicking the workbook? Kobayashi[_44_] Excel Programming 2 October 28th 04 10:15 PM
Can a workbook variable be set by clicking the workbook? Kobayashi[_46_] Excel Programming 0 October 28th 04 08:55 PM
Can a workbook variable be set by clicking the workbook? Kobayashi[_43_] Excel Programming 2 October 28th 04 06:20 PM


All times are GMT +1. The time now is 06:53 PM.

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

About Us

"It's about Microsoft Excel"