Workbooks.Open Error

reneuend

Board Regular
Joined
May 20, 2009
Messages
155
I created the following function which was working fine for the past couple days while testing, until now.

I'm getting an error on the line: Workbooks.Open FileName:=FileToOpen

Error Msg: Method 'Range' of object '_Global' failed

Code:
Function Get_FileToOpen()
 
    FileToOpen = Application.GetOpenFilename _
    (Title:="Please choose a file to import", _
    FileFilter:="Excel Files *.xls (*.xls),")
    ''
    If FileToOpen = False Then
        MsgBox "No file specified.", vbExclamation, "Please Try Again."
        Get_FileToOpen = ""
    Else
    Debug.Print FileToOpen
        Workbooks.Open FileName:=FileToOpen
        Get_FileToOpen = FileToOpen
    End If
 
End Function

FileToOpen variable has the following value which is 155 characters in length:

C:\Documents and Settings\BN0061\My Documents\EXCEL VBA\Family Care\Winder Model\enhancement08\Family Care Converting Winding Model v8 - test archiving.xls

:confused:Any ideas of why this would cause an error? The only thing different in the test is the filename. I had tested a file earlier in the same location. Interestingly, the file does open when this function is called, but still throws the error.

I'm using Excel 2003, but will test later in Excel 2007.

thanks for any help.
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,224,613
Messages
6,179,894
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top