ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   GetOpenFileName to select a .URL file (https://www.excelbanter.com/excel-programming/409753-getopenfilename-select-url-file.html)

Gary''s Student

GetOpenFileName to select a .URL file
 
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

joel

GetOpenFileName to select a .URL file
 
The excel FILE commands don't want to see the "http:" as part of the file
name. HTTP is the protocol for transfering the file, not the name. You can
open a file by using "//root/subdirect/abc.xls". Don't use
"http://root/subdirect/abc.xls"

To be able to see network files, you have to mount the network directory on
you computer. You can do in the windows explorer (not internet) using the
menu Tools - Mount Network Drive. Once the Netwrok dirive is mounted then
you can use GetOpenFilename.

"Gary''s Student" wrote:

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


Zack Barresse

GetOpenFileName to select a .URL file
 
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



Gary''s Student

GetOpenFileName to select a .URL file
 
Thank you Joel. I am, however, not trying to open the file, just get its
full path-name. If we run the code, it brings up the Open File Dialog. If
we pick a file using the Dialog, the msgbox displays the full path-filename.
For all files except .url files.

I need something to work for all files type in the same way.
--
Gary''s Student - gsnu200781


"Joel" wrote:

The excel FILE commands don't want to see the "http:" as part of the file
name. HTTP is the protocol for transfering the file, not the name. You can
open a file by using "//root/subdirect/abc.xls". Don't use
"http://root/subdirect/abc.xls"

To be able to see network files, you have to mount the network directory on
you computer. You can do in the windows explorer (not internet) using the
menu Tools - Mount Network Drive. Once the Netwrok dirive is mounted then
you can use GetOpenFilename.

"Gary''s Student" wrote:

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


Gary''s Student

GetOpenFileName to select a .URL file
 
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



Rick Rothstein \(MVP - VB\)[_1786_]

GetOpenFileName to select a .URL file
 
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



Rick Rothstein \(MVP - VB\)[_1787_]

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




Zack Barresse

GetOpenFileName to select a .URL file
 
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




Gary''s Student

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




Gary''s Student

GetOpenFileName to select a .URL file
 
Hi Rick:

The code works perfectly!

Thanks for coming to my rescue (once again)!
--
Gary''s Student - gsnu200781


"Rick Rothstein (MVP - VB)" wrote:

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




Rick Rothstein \(MVP - VB\)[_1791_]

GetOpenFileName to select a .URL file
 
The code works perfectly!

Great!

Thanks for coming to my rescue..


I'm always glad to help out where I am able to.

Rick


All times are GMT +1. The time now is 10:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com