Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
macro
hi, im using code
'Macro purpose: Use the application.run method to execute 'a macro without arguments from another workbook Dim PathToFile As String, _ NameOfFile As String, _ wbTarget As Workbook, _ CloseIt As Boolean 'Set file name and location. You will need to update this info! NameOfFile = "German Home Results Predictor 2007.xls" PathToFile = "C:\Documents and Settings\Robert\Desktop\FOOTBALL \Soccer Predictions\german\Home" 'Attempt to set the target workbook to a variable. If an error is 'generated, then the workbook is not open, so open it On Error Resume Next Set wbTarget = Workbooks(NameOfFile) If Err.Number < 0 Then 'Open the workbook Err.Clear Set wbTarget = Workbooks.Open(PathToFile & "\" & NameOfFile) CloseIt = True End If 'Check and make sure workbook was opened If Err.Number = 1004 Then MsgBox "Sorry, but the file you specified does not exist!" _ & vbNewLine & PathToFile & "\" & NameOfFile Exit Sub End If On Error GoTo 0 'Run the macro! (You will need to update "MacroName" to the 'name of the macro you wish to run) Application.Run (wbTarget.Name & "!collectdata") If CloseIt = True Then 'If the target workbook was opened by the macro, close it wbTarget.Close savechanges:=True Else 'If the target workbook was already open, reactivate this workbook ThisWorkbook.Activate to run a macro from one work book to another. When I try to run the macro I get the error cannot find....Yet Ive used this with a different macro inanother workbook and it runs perfect. I wondering if theres a setting that could be on in one workbook but not the other. Any advice appreciated. RegardsRobert |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
AutoRun Macro with a delay to give user the choice to cancel the macro | Excel Programming | |||
Macro not showing in Tools/Macro/Macros yet show up when I goto VBA editor | Excel Programming | |||
Need syntax for RUNning a Word macro with an argument, called from an Excel macro | Excel Programming | |||
how to count/sum by function/macro to get the number of record to do copy/paste in macro | Excel Programming | |||
Start Macro / Stop Macro / Restart Macro | Excel Programming |