Macro for opening another workbook
Macro for opening a workbook
Dim PathToFile As String
Dim NameOfFile As String
Dim wbTarget As Workbook
NameOfFile = “Daily”
PathToFile = “C:\Documents and Settings\175858\Desktop\”
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)
ThisWorkbook.Activate
a11 = Sheet1.Cells(1, 2)
Workbooks(”MacroWen.xls”).Activate
Sheet1.Cells(100, 1) = a11
End Sub