Selecting a file in VBA
Selecting a file in VBA
(OP)
Hi there,
Does anyone know how to display a file open dialog and retrieve the name of the file that the user opens. At the moment I can display the dialog and ascertain if they click OK or Cancel but I cannot find out which file they selected.
Any help much appreciated :)
Miles Macklin
Does anyone know how to display a file open dialog and retrieve the name of the file that the user opens. At the moment I can display the dialog and ascertain if they click OK or Cancel but I cannot find out which file they selected.
Any help much appreciated :)
Miles Macklin





RE: Selecting a file in VBA
dlg.Filter = "SolidWorks Part File (*.SLDPRT)|*.SLDPRT"
dlg.InitDir = "C:\Test\"
dlg.ShowSave
sFileName = dlg.FileName
sPartName = dlg.FileTitle
GetFileName = True
If Len(sFileName) = 0 Then
GetFileName = False
MsgBox "Cancelled!"
ElseIf Dir(sFileName) <> "" Then
s1 = sFileName & vbCrLf & "Already Exists." & vbCrLf & _
& "Should I overwrite the file?"
UsrRes = MsgBox(s1, vbYesNo + _
vbDefaultButton2, "Overwrite Existing File?")
If UsrRes = vbNo Then
MsgBox "Orignal File Preserved!", vbOKOnly, _
"New File Not Saved!"
GetFileName = False
Else
Kill sFileName
End If
End If
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Selecting a file in VBA
appreciated if someone give me an idea how to get Microsoft Common Dialog Control at all?
thanks
RE: Selecting a file in VBA
RE: Selecting a file in VBA
Try function: application.GetOpenFilename. It displays open file dialog box and returns the selected file.