Excel VBA Macro: Allow User to Select File to Open (with Dialog Box)

preview_player
Показать описание
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

anonomyss
Автор

Thanks for the tutorial - helped with a work task and was the least complicated version!

ryancollins
Автор

This is awesome!! it helps me with my project. simple explanation but powerful. Thanks for sharing. 😁

clarencereireyes
Автор

You are great! Code works perfectly fine👍 thank you so much

adarshVernekar-eztt
Автор

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.

Shiftkeycom
Автор

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.

rogerferreira
Автор

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?

ldkNsc
Автор

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

ricabude
Автор

.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

j.reneewilliams