Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refering to workbooks using a variable

Status
Not open for further replies.

paulo33

Technical User
Oct 31, 2002
15
0
0
AU
Anybody know how to refer to a workbook, using a variable??

My procedure asks the user to input the name of the excel workbook to open, asigns this filename to a variable, and opens it. Then I need to call this opened workbook, from the original procedure, but I don´t know how to refer to it using the original variable which stores the workbook name.

 
When you open a workbook, it becomes the active book:
[blue]
Code:
Option Explicit

Sub test()
Dim sWork As String
  sWork = "c:\JulySummary.xls"
  OpenMyBook sWork
End Sub

Sub OpenMyBook(ABookName As String)
Dim oWorkbook As Workbook
  Workbooks.Open ABookName
  Set oWorkbook = ActiveWorkbook
  MsgBox oWorkbook.Name
  Set oWorkbook = Nothing
End Sub
[/color]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top