Excel VBA Macro: Allow User to Select File to Open (with Dialog Box)
HTML-код
- Опубликовано: 2 окт 2021
- Excel VBA Macro: Allow User to Select File to Open (with Dialog Box). In this video, we go over how to allow a user to be prompted to select a file and then open the selected file. We also change the title and button names in the Dialog Box and specify how many files the user is allowed to select.
Code:
Sub select_file()
Dim FilePicker As FileDialog
Dim mypath As String
Set FilePicker = Application.FileDialog(msoFileDialogFilePicker)
With FilePicker
.Title = "Please Select a File"
.AllowMultiSelect = False
.ButtonName = "Confirm"
If .Show = -1 Then
mypath = .SelectedItems(1)
Else
End
End If
End With
Workbooks.Open Filename:=mypath
End Sub
#ExcelVBA #ExcelMacro
I just need a quick and simple solution to how to open workbooks and everything I found was so huge and complicated. This was PERFECT for my situation and so easy to follow. Thank you so much!!!!!!!!
No problem! So glad to hear that!!
Thanks for the tutorial - helped with a work task and was the least complicated version!
No prob! Glad to hear that!!
This is awesome!! it helps me with my project. simple explanation but powerful. Thanks for sharing. 😁
So glad to hear that! Thanks for watching!!
You are great! Code works perfectly fine👍 thank you so much
Thank you!!
Thank you this is great!
So glad to hear that! Thanks for watching!!
This was awesome! thank you
Thank you for watching!!
Question-
Can you advise on the necessary vba code to create a custom menu? Custom menu would be at top of shortcut menu, include 2 sub menus "Formatting" & "Standard". Each sub menu would include youtube links and local folder links.
Appreciate the help.
Thank you.
You’re welcome!
Hi, Very nice tuto. I'm trying to open a CSV file but nothing happen. Do you have a tip for me ? Thanks in advance.
Thanks so much for this! I have been searching the web for a week when I stumbled onto your video. It's just what I've been looking for! But is there a way that multiple files can be selected and opened?
So glad to hear that. Thanks for watching! Yes, I’ll make a video on that soon, but you would start by setting AllowMultiSelect = True
Hi, thanks for the video, this is exaclty what I need. However, on running your macro I get a message error that "object variable, or block variable, not defined", and the script halts on the line ".Title =....". Macros for windows and macs differ in any way (I'm on a mac)? Do you have any ideas why this is happening? Thanks again for your help
No problem! Yeah, the way Mac and windows reference files is different. I’ll make a video for macs soon
.title = “Please Make One Selection” is causing Run time error ‘91’: Object variable or with Block variable not set.
(Just in case it matters, I am on a MacBook Pro). Thx
You’ll have to use different code for a MacBook. I’ll make a video specifically for that
@@greggowaffles , did you ever make the video for MacBook for this same code? I could really use it as I am getting the same error.