Passing a variable into a subroutine in a different open workbook
I am trying to pass on a variable called by a subroutine in a macro written
in a different workbook. The variable is the filename of the workbook where the first macro is written. I didn't get an error with both of the following lines of code, but it just stopped running. Can you help? FirstWb = ThisWorkbook.Name ActiveWbMacro = SecondWb &* "!RunMacro2(""" & FirstWb & """)" Application.Run ActiveWbMacro I also tried: ActiveWbMacro = "'" & SecondWb &* "'!RunMacro2(""" & FirstWb & """)" Application.Run (ActiveWbMacro) Thanks for your help! |
Passing a variable into a subroutine in a different open workbook
This worked fine for me.
I put this in a general module in Book3.xls's project: Option Explicit Sub runmacro2(mystr As String) MsgBox mystr End Sub And I called it this way: Option Explicit Sub testme() Dim FirstWb As String Dim SecondWb As String Dim ActiveWbMacro As String SecondWb = Workbooks("book3.xls").Name FirstWb = ThisWorkbook.Name ActiveWbMacro = "'" & SecondWb & "'!RunMacro2" Application.Run ActiveWbMacro, FirstWb End Sub ActDude wrote: I am trying to pass on a variable called by a subroutine in a macro written in a different workbook. The variable is the filename of the workbook where the first macro is written. I didn't get an error with both of the following lines of code, but it just stopped running. Can you help? FirstWb = ThisWorkbook.Name ActiveWbMacro = SecondWb &* "!RunMacro2(""" & FirstWb & """)" Application.Run ActiveWbMacro I also tried: ActiveWbMacro = "'" & SecondWb &* "'!RunMacro2(""" & FirstWb & """)" Application.Run (ActiveWbMacro) Thanks for your help! -- Dave Peterson |
Passing a variable into a subroutine in a different open workb
This worked great. Thanks!
"Dave Peterson" wrote: This worked fine for me. I put this in a general module in Book3.xls's project: Option Explicit Sub runmacro2(mystr As String) MsgBox mystr End Sub And I called it this way: Option Explicit Sub testme() Dim FirstWb As String Dim SecondWb As String Dim ActiveWbMacro As String SecondWb = Workbooks("book3.xls").Name FirstWb = ThisWorkbook.Name ActiveWbMacro = "'" & SecondWb & "'!RunMacro2" Application.Run ActiveWbMacro, FirstWb End Sub ActDude wrote: I am trying to pass on a variable called by a subroutine in a macro written in a different workbook. The variable is the filename of the workbook where the first macro is written. I didn't get an error with both of the following lines of code, but it just stopped running. Can you help? FirstWb = ThisWorkbook.Name ActiveWbMacro = SecondWb &* "!RunMacro2(""" & FirstWb & """)" Application.Run ActiveWbMacro I also tried: ActiveWbMacro = "'" & SecondWb &* "'!RunMacro2(""" & FirstWb & """)" Application.Run (ActiveWbMacro) Thanks for your help! -- Dave Peterson |
All times are GMT +1. The time now is 01:03 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com