PDA

View Full Version : Embed an "open file" dialogue box to userform, Excel 64 bit version



JangLabs
12-25-2016, 04:46 AM
Hello folks, I'm trying to add a standard "File Open" dialogue box into a userform, in Excel 2016 64-bit version.

(1) There is a way to do this in Excel 32-bit version:
In short, [VBA Editor - Tools - Additional Controls - Microsoft Common Dialog Controls] would add File Open diaglogue box to the VBA Editor toolbox.
But in 64-bit Excel, "Microsoft Common Dialog Controls" is not available.

(2) If I were not adding this "File Open" dialogue box to a userform, it is pretty easy to just launch the "File Open" dialogue box using "Application.FileDialog(msoFileDialogFilePicker)". This is not what I am trying to do.
What I am trying to do is to embed an "open file" button/dialogue box to a userform that has several other buttons.

Can anyone help? Thank you in advance!

IJ, Seoul

mikerickson
12-25-2016, 04:00 PM
You could add an appropriately captioned Command Button


Private Sub CommandButton1_Click()
Dim FileChosen as String
Application.FileDialog(msoFileDialogFilePicker)
If FileChosen <> "False" Then
TextBox1.Text = FileChosen
End If
End Sub

JangLabs
01-02-2017, 10:35 PM
Hey Mike, really appreciate your response. The forum rocks!
I made a small adjustment (".Show")


Private Sub CommandButton1_Click()
Dim FileChosen As String
Application.FileDialog(msoFileDialogFilePicker).Show
If FileChosen <> "False" Then
TextBox1.Text = FileChosen
End If
End Sub

Would you be so kind as to let me know how I can actually capture the information provided by the user?
That is, so the userform shows up, the user clicks the command button, and gets the file open dialog box -- when the user selects a file, how can I store the user's selection (that is, file path including file name) into a variable? Where I am getting confused with the above is, I don't think the "FileChosen" variable above captures the information.

Thank you in advance!

mikerickson
01-03-2017, 06:05 PM
I would try this

Private Sub CommandButton1_Click()
Dim FileChosen As String
FileChosen = Application.FileDialog(msoFileDialogFilePicker).Show
If FileChosen <> "False" Then
TextBox1.Text = FileChosen
End If
End Sub


(or to be really fancy)


Private Sub CommandButton1_Click()
Dim FileChosen As String

#If Mac Then
fileChosen = "False"
On Error Resume Next
fileChosen = MacScript("return choose folder")
On Error GoTo 0
fileChosen = Replace(fileChosen, "alias ", vbNullString, , 1)
#Else
FileChosen = Application.FileDialog(msoFileDialogFilePicker).Show
#End If

If FileChosen <> "False" Then
TextBox1.Text = FileChosen
End If
End Sub

SamT
01-03-2017, 09:46 PM
FileChosen is the Variable that holds the User's selected File Path+Name. Or "False".

snb
01-04-2017, 01:30 AM
Private Sub CommandButton1_Click()
with Application.FileDialog(1)
if .Show then c00=.selecteditems(1)
end with
End Sub

c00 is the variable that holds the fullname