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

This entry was posted on Wednesday, December 17th, 2008 at 9:22 am and is filed under Webmaster. You can follow any responses to this entry through the RSS 2.0 feed. Responses are currently closed, but you can trackback from your own site.

Comments are closed.