Variable Not Updating in Call to Macro in Another Workbook

cbrendlinger

New Member
Joined
Feb 7, 2012
Messages
8
I have a macro that I want to house in a separate Workbook so that I can call it from multiple macros in multiple Workbooks. The call to the macro seems to work but the variable that I am looking for does not update in the calling macro. The value returned is empty. Here is what I have:

The Macro being called:
Option Explicit

Public Logo_Name As String

Public Function Get_Logo_Name(Ref_URL As String, LogoName As String) As String

If ((Ref_URL = "/www.website.com/client1/")) Then
LogoName = "Client1"
ElseIf ((Ref_URL = "/www.website.com/client2/")) Then
LogoName = "Client2"
Else
LogoName = "None"
End If

Logo_Name = LogoName

End Function

The code calling the macro above:

Sub A_Get_Answers()

Dim AltWorkbookName As String
Dim MacroName As String
Dim folderpath As String
Dim subpath As String
Dim LogoName As String
Dim wb As Workbook

folderpath = Application.ThisWorkbook.Path
subpath = Left(folderpath, InStrRev(folderpath, "\") - 1)
AltWorkbookName = subpath & "\Current Application\AALogoPull.xlsm"
MacroName = "Get_Logo_Name"
Set wb = Workbooks.Open(AltWorkbookName, , True)
Application.Run "'" & wb.Name & "'!" & MacroName, Ref_URL, LogoName
MsgBox wb.Logo_Name

End Sub

The value of wb.Logo_Name is always blank. All I am trying to do is retrieve that value. I am sure that I am missing something (hopefully simple) but I just don't know what. I really appreciate any insight. Thank you!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
In which module is Logo_Name declared? It would have to be in the ThisWorkbook module of the other workbook (and nowhere else).
 
Upvote 0
I know but in which module in that workbook is that code?
 
Upvote 0
Then you should be getting an error. This line:

Code:
Public Logo_Name As String

must be in the ThisWorkbook module of that workbook, and the code line to set it should be:

Code:
ThisWorkbook.Logo_Name = LogoName

not:

Code:
Logo_Name = LogoName
 
Upvote 0
Solution
Glad we could help. :)
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top