goss
Active Member
- Joined
- Feb 2, 2004
- Messages
- 372
Hi all,
Using Ecxel 2010
I Googled and found some code for GetOpenFileName from Bill Jelen et al
I cobbled it together
At the moment, it prompts me to select a file which I do, but the a Run-time error 91 is returned (Object variable not set) and the file is not open
I tried adding Set here
But that cast Run-time error 424 "Object Required"
What am I doing wrong?
Thanks
g
Full snippet:
Using Ecxel 2010
I Googled and found some code for GetOpenFileName from Bill Jelen et al
I cobbled it together
At the moment, it prompts me to select a file which I do, but the a Run-time error 91 is returned (Object variable not set) and the file is not open
I tried adding Set here
Code:
wbImport = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", _
Title:="Please select a file")
to
Set wbImport = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", _
Title:="Please select a file")
But that cast Run-time error 424 "Object Required"
What am I doing wrong?
Thanks
g
Full snippet:
Code:
Option Explicit
Sub GetFile2()
Dim wb As Workbook
Dim wbImport As Workbook
Dim ws As Worksheet
Dim strPath As String
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Data")
strPath = "C:\Users\dlee\Documents\Financial Analysis\Forecast" '<--Change as needed
ChDir strPath
wbImport = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", _
Title:="Please select a file")
If wbImport = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=wbImport
End If
Set wb = Nothing
Set ws = Nothing
End Sub