Workbook name as variable to another workbook

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Can you save a specific workbook name as a variable, to be used in a
different macro? i need the variable to be saved and available to return to
the specific workbook open if i have a lot of books open to complete the task.

Regards,

nigel
 
Option Explicit
Dim myWkbkName As String
Sub runmefirst()
myWkbkName = ThisWorkbook.Name
End Sub
Sub runmesecond()
MsgBox myWkbkName
End Sub

If you execute runmefirst first, then runmesecond, you'll see that myWkbkname is
available in the second.

If you need to put the routines in different modules, declare myWkbkName as
Public:
Public myWkbkName As String
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top