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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with Application.GetOpenFileName!!!

Status
Not open for further replies.

Paco75

Programmer
Oct 11, 2001
239
US
Hi,

Im using Application.GetOpenFileName in my excel macro and it dosent work on computers who have office 2000 and olders ones! I get an error message saying "Application.GetOpenFileName" failed... like if this method is not in office 2000? (I'm using Excel XP)

So I want to know another dialog window to open a file...

thanks a lot!
 
By searching I found this:

It should open a standard file open dialog box! You might have to modify some things to get this running in vba... like "Me.hWnd" use FindWindow instead... and so on. I didin't make it work up to now but I think It's possible.

Hope it helps...

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Sub Form_Load()
'KPD-Team 1998
'URL: 'E-Mail: KPDTeam@Allapi.net
Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hwndOwner = Me.hWnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Select a filter
OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'create a buffer for the file
OFName.lpstrFile = Space$(254)
'set the maximum length of a returned file
OFName.nMaxFile = 255
'Create a buffer for the file title
OFName.lpstrFileTitle = Space$(254)
'Set the maximum length of a returned file title
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the title
OFName.lpstrTitle = "Open File - KPD-Team 1998"
'No flags
OFName.flags = 0

'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
MsgBox "File to Open: " + Trim$(OFName.lpstrFile)
Else
MsgBox "Cancel was pressed"
End If
End Sub


cheers!!!
 
Application.getopenfilename works just fine in Excel2000. There must be something else going on in your case.
Rob
[flowerface]
 
Really! Ok then I will test on another PC...
 
You were right! It worked on anether PC we have...
I looked at the version numbers and the working ones have excel version 9.0.2720 and the others have excel version 9.0.3821 (SR-1). It says that an object is not found!
 
In the VBA editor, Click Tools/References...

Check the box for "Microsoft Forms 2.0 Object Library" (That is for Excel 97 - you may see a different version referenced.)

Click Ok.

On my machine, it refers to c:\windows\system\fm20.dll

 
Hi Zathras,

I already got that reference check... the problem happens on some PC only... those who have Office 2000 for Small Buisness (v 9.0.3821)... others Office 2000 are working! Seems to be a Office configuration problem!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top