View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1787_] Rick Rothstein \(MVP - VB\)[_1787_] is offline
external usenet poster
 
Posts: 1
Default GetOpenFileName to select a .URL file

And the link I forgot to post is...

http://msdn2.microsoft.com/en-us/lib...39(VS.85).aspx

Rick


Give the code after my signature a try... I think it does what you want.
Note that this link (for C++) has a listing of the various constants that
can be set for the "flags" member of the OPENFILENAME Type (structure),
although the actual values are not shown and will need to be Googled for.
The subroutine you will call is named PickOne (like your own subroutine
was named).

Rick

**************** START OF CODE ****************
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 PickOne()
Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hwndOwner = Application.Hwnd
'Set the application's instance
OFName.hInstance = Application.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 = "Get Path And Filename"
'No flags
OFName.flags = 0
'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
MsgBox Trim$(OFName.lpstrFile)
Else
MsgBox "Cancel was pressed"
End If
End Sub
**************** END OF CODE ****************



"Gary''s Student" wrote in
message ...
I need to pick a file (including the path), I have:

Sub pickOne()
s = Application.GetOpenFilename
MsgBox (s)
End Sub

to select a file. If I select a .xls file, I see the full path and file
name:

C:\Temp\x.xls

If I select an internet shortcut, I see:
http://www.cnn.com

What I need is:
C:\Temp\x.url
the full path and filename


Can I get GetOpenFileName to give me the full path and filename, or
should I
be using something else?
--
Gary''s Student - gsnu200781