Excel macro

Toshiba Portege M200
July 3, 2008 at 13:01:15
Specs: XP Pro 5.1, SP2, 1.80GHz / 512 MB

I have created an Excel workbook that uses control buttons to run macros and that also uses '' to run macros within other macros. But when this workbook is renamed by various people for their own use, the references to these macros retain the original workbook name. Is there a way to use "ActiveWorkbook" or another reference instead of the workbook name? So far my attempts have failed. Example:

Private Sub CommandButton1_Click()
Application.Run "'syllabication tool.xls'!paste_special"
End Sub

Thanks for your help!

See More: Excel macro

Report •

July 3, 2008 at 20:10:26

Take a look at the ThisWorkbook property in VBA help. Maybe that'll work.

Report •

July 7, 2008 at 06:15:35

Thanks for the suggestion. I can't find any discussion of how to refer to a macro using ThisWorkbook instead of the workbook name. I'm not sure whether ThisWorkbook is on the right track or wrong track. (I'm learning VBA as I go, here.) :)

Report •

July 7, 2008 at 06:41:48

Try something like this -

The code that calls the ThisWorkbook code (in this case "CallerExample") can be placed in any module, but the code that is being called (in this example "DoThis") must be placed in the ThisWorkbook module.

Sub CallerExample()
End Sub

Sub DoThis()
MsgBox "Message"
End Sub

Report •

Related Solutions

July 8, 2008 at 09:34:36

That did it! Thanks so much. Also thanks for modeling a simpler way to run a macro within a macro (instead of "Application.Run")

Report •

July 8, 2008 at 20:43:06

Glad to have been of assistance.

Report •

Ask Question