Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getopenfilename runtime error 13 type mismatch 3

Status
Not open for further replies.

Walter349

Technical User
Aug 16, 2002
250
BE
Had a search but could not find anything that addressed this issue.

When running the following code I get the above error, As only one file will be selected at any time, going for the array approach seems excessive.

The files to be opened are all xls extension, running under Excel MSO 2010

Any ideas what I am failing to understand?

Code:
Private Sub CommandButton2_Click()
Dim NewFN As String
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files(*.xls),*.xls", Title:="Select File Name to Open", MultiSelect:=False)
If NewFN = False Then
    MsgBox "No File was selected"
    Exit Sub
Else
    Workbook.Open NewFN
End If
End Sub

'If at first you don't succeed, then your hammer is below specifications'
 
Replace this:
Dim NewFN As String
with this:
Dim NewFN As Variant

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Thanks for the repy,

I had already tried that, but it merely changes the error code to 424, Object required. Which did not help at all. If I was wanting to open a number of files at a time and pass them to an array, then a vairant would be the way I would go.

But in this case only one file is to be opened and actioned by the user, at a time. So a string variable to my mind should do the job.

Why it errors is the question that remains.

'If at first you don't succeed, then your hammer is below specifications'
 
It doesn't really 'change' the error. Having fixed one error you then stumble over another. The 'Object required' is "Workbook"; because you don't have an "Option Explicit" the compiler isn't checking for silly typos and it is only at run-time that you trip over them - make it "Workbooks" and all should be well.


Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Thanks for the assist.

'If at first you don't succeed, then your hammer is below specifications'
 


Code:
Private Sub CommandButton2_Click()
Dim NewFN As [b]Variant[/b]
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files(*.[b]xls*),*.xls*[/b]", Title:="Select File Name to Open", MultiSelect:=False)
If NewFN = False Then
    MsgBox "No File was selected"
    Exit Sub
Else
    Workbook[b][red]s[/red][/b].Open NewFN
End If
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks Skip,

Thats a good thought. The documents are supposed to be 97-2003 friendly, but things do get stuffed up sometimes.

'If at first you don't succeed, then your hammer is below specifications'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top