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

Комментарии • 23

  • @anonomyss
    @anonomyss 2 года назад +1

    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!!!!!!!!

  • @ryancollins3025
    @ryancollins3025 Год назад

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

  • @clarencereireyes4130
    @clarencereireyes4130 Год назад

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

    • @greggowaffles
      @greggowaffles  Год назад

      So glad to hear that! Thanks for watching!!

  • @adarshVernekar-ez5tt
    @adarshVernekar-ez5tt 3 месяца назад

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

  • @virginiagould3167
    @virginiagould3167 2 года назад

    Thank you this is great!

    • @greggowaffles
      @greggowaffles  2 года назад

      So glad to hear that! Thanks for watching!!

  • @user-vr5qg7mw4q
    @user-vr5qg7mw4q Год назад

    This was awesome! thank you

  • @Shiftkeycom
    @Shiftkeycom Год назад

    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.

  • @rajivjoshi3392
    @rajivjoshi3392 Год назад

    Thank you.

  • @rogerferreira1997
    @rogerferreira1997 Год назад

    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.

  • @ldkNsc
    @ldkNsc 2 года назад

    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?

    • @greggowaffles
      @greggowaffles  2 года назад

      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

  • @ricabude
    @ricabude 2 года назад

    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

    • @greggowaffles
      @greggowaffles  2 года назад

      No problem! Yeah, the way Mac and windows reference files is different. I’ll make a video for macs soon

  • @j.reneewilliams8375
    @j.reneewilliams8375 2 года назад

    .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

    • @greggowaffles
      @greggowaffles  2 года назад

      You’ll have to use different code for a MacBook. I’ll make a video specifically for that

    • @JimHearn
      @JimHearn 5 месяцев назад

      @@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.