Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call a subroutine using variable subroutine name dhstein Excel Discussion (Misc queries) 3 July 26th 09 08:28 PM
How to check workbook is already opened before passing the workbook obj to a subroutine in Word Bon Excel Programming 2 January 19th 06 09:54 AM
Auto Open and Passing variable value(s) to MS Word Sony[_2_] Excel Programming 1 September 29th 03 05:00 AM
Passing a variable to a Worksheet at open time Neil Excel Programming 0 September 18th 03 03:52 PM
Passing a Variable from Worksheet to Workbook Susan Lammi Excel Programming 6 August 3rd 03 01:29 AM


All times are GMT +1. The time now is 04:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"