In a VBPJ Tip I got the following I was wondering if it works for anyone. I made a few changes laving the old code in place. (It didn't work in the first place) What I really desire is a better way to getfilenames from users.
' Add a reference to DlgObjs to your project by selecting
' Microsoft Dialog Automation Objects from the Project References dialog.
' This code [should] returns a filename:
'Public Function GetFile(WinHandle As Long) As String
Public Function GetFile() As String
Dim Dlg As ChooseFile
On Error Resume Next
Set Dlg = New ChooseFile
With Dlg
.Save = False ' dont want a Save As dialog box.
.Center = True ' We want the dialog centered.
.hWnd = Screen.ActiveControl.Parent.hWnd ' handle
'.hWnd = WinHandle ' Need a parent window.
.HideReadOnly = True ' Don't need the 'Open as Read Only' box.
.MultiSelect = False ' Don't select multiple files.
.OverwritePrompt = True ' Ask to overwrite an existing file.
'.Filters.Add "BAS Files (*.bas):*.bas" ' File mask.
.Filters.Add "All Files (*.*):*.*" ' File mask.
If .Show Then
GetFile = .Directory & "\" & .FileName
'GetFileName = .Directory & "\" & .FileName
Else
GetFile = "" ' User pressed Cancel
'GetFileName = "" ' User pressed Cancel
End If ' The printed tip didn't have this line (think it ran? :/)
End With
Set Dlg = Nothing
End Function
~Joe Johnston USA
"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams