running excel 2010 on windows 7. trying to open Book2.xlsx from Book1.xlsm. this hard-coded macro works:
Sub Macro3()
Workbooks.Open Filename:="C:\Users\steve\Book2.xlsx", UpdateLinks:=True, ReadOnly:=True
Workbooks("book2.xlsx").Activate
End Sub
This function doesn't (no error on the workbooks.open line, but wb throws object variable or with block variable not set. Passing "c:\users\steve\Book2.xlsx" as FileToOpen param
Public Function OpenWorkbook1(FileToOpen As String) As String
Dim wb As Workbook
On Error GoTo ErrTrap
If Dir(FileToOpen) <> "" Then
Set wb = Workbooks.Open(FileToOpen, 0, True)
Debug.Print wb.Name
OpenWorkbook1 = "Opened " & FileToOpen
Else
OpenWorkbook1 = FileToOpen & " doesn't exist."
End If
Exit Function
ErrTrap:
MsgBox Err.Number & " " & Err.Description, vbOKOnly, " Error from OpenWorkbook"
OpenWorkbook1 = "Failed to Open " & FileToOpen
Exit Function
End Function
Bookmarks