![]() |
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 |
All times are GMT +1. The time now is 06:10 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com