Declaring Variables

M

matt_steer

Probably v simple.....

What is the code for defining a variable to be the name of an exec
work book?

I have a macro within a template that needs to assign a variable to b
a name of the workbook created from the template.

Cheers
 
P

pikus

Well if you want the variable to hold the NAME of the workbook:

Dim strWkBkNam As String
strWkBkNam = "Workbook.xls"

BUT, if you want the variable to be an object reference to the workboo
itself:

Dim WkBk1 As Workbook
Set WkBk1 = Workbooks("Workbook.xls")

Note the use of the "Set" keyword. This must always be used wit
object variables. - Piku
 
B

Bob Phillips

or

strWkBkName = Activeworkbook.Name

or

strWkBkName = ThiwWorkbook.Name

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top