Calling Procedures in Another Workbook and Passing Variables

ExcelKid_10

Board Regular
Joined
Mar 17, 2004
Messages
87
Hello-

I have a VBA Routine where I open workbook and run some code in the newly opened workbook that requires two input parameters...I've been trying to pass them ByVal however the debugger now does not recognize the Call to the procedure if I include the variables...anybody have any ideas on how I remedy this?

Here is my code:

Function OpenExcelPerfAttributionDataFile()
Dim xlApp As Object
Dim xlWb As Object
Dim xlWS As Worksheet
Dim strSheet, strFileName As String
Dim strBegDate, strEndDate, xDate As String

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True

strEndDate = DMax("[tblDates]![Report_Date]", "tblDates")
xDate = DateSerial(Year(strEndDate), Month(strEndDate) - 1, Day(strEndDate))
strBegDate = Format(xDate, "MM/DD/YYYY")


strFileName = "PerformTotalReturnLoader.xls"
sFile = "\\faffsprd\fs31_fite$\Quant\Reporting Database And Directions\" & strFileName

Set xlWb = xlApp.Workbooks.Open(sFile, True)

'*****Code crashes on this line....
sMacro = "UpdatePerformanceLoader(" & strBegDate & "," & strEndDate & ")"
'
xlApp.Run sMacro

'xlWb.Close (True) '<saves it

xlApp.Quit

Set xlWS = Nothing
Set xlWb = Nothing
Set xlApp = Nothing

End Function

Thanks!

EK
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I guess something like this would work:
Code:
xlApp.Run PerformTotalReturnLoader.xls!UpdatePerformanceLoader(strBeginDate,strEndDate)

Or keeping the workbook name in a variable, maybe like (not tested though):
Code:
xlApp.Run Workbooks(strFileName)!UpdatePerformanceLoader(strBeginDate,strEndDate)
 
Upvote 0
Scratch that. All baloney.
I think you just need to add the workbook name:

Code:
sMacro = [B][COLOR="RoyalBlue"]strFileName & "!" & [/COLOR][/B]"UpdatePerformanceLoader(" & strBegDate & "," & strEndDate & ")"

Does that work?
 
Upvote 0
Code:
xlApp.Run "'" & wb.Name & "'!UpdatePerformanceLoader", strBegDate, strEndDate
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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