View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default GetOpenFileName to select a .URL file

Thank you Zack. Your code is just what I need.
--
Gary''s Student - gsnu200781


"Zack Barresse" wrote:

Mine was similar to Rick's, but uses the same API...


Option Explicit

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

Sub Open_Comdlg32()
'Originally from Ivan F. Moala: http://www.xcelfiles.com/comdlg.html
Dim OpenFile As OPENFILENAME, lReturn As Long, strFilter As String,
FileToOpen As String
OpenFile.lStructSize = Len(OpenFile)
strFilter = "My Files (*.url)" & Chr(0) & "*.url" & Chr(0)
With OpenFile
.lpstrFilter = strFilter
.nFilterIndex = 1
.lpstrFile = String(257, 0)
.nMaxFile = Len(.lpstrFile) - 1
.lpstrFileTitle = .lpstrFile
.nMaxFileTitle = .nMaxFile
.lpstrInitialDir = "C:\Users\Zack\Desktop\"
.lpstrTitle = "My FileFilter Open"
.flags = 0
End With
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "User cancelled"
Else
FileToOpen = Application.WorksheetFunction.Clean(OpenFile.lpstr File)
MsgBox FileToOpen, vbInformation, "FILE PATH & NAME"
End If
End Sub



HTH


--
Zack Barresse



"Gary''s Student" wrote in message
...
Thank you Zack.

Using your suggestion does restrict the files displayed in the Dialog box.
If I click on a file with the extension .url, I do not get the
path-filename,
I still get the url value itself.

I don't need and don't want the target of the url:

http://www.......

I need the path and file name of the file I selected in the Dialog box:

C:\Documents and Settings\Owner\Favorites\news.url
--
Gary''s Student - gsnu200781


"Zack Barresse" wrote:

You're wanting to use the GetOpenFileName() to get the file name/path of
a
file with the extension "url"? Just use that as your passed syntax for
file
types, which you can use to filter it out. A google search will yield
many
results.

--
Zack Barresse


"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