Home Excel Powerpoint Word Outlook Error Codes

VBA Useful Codes

Welcome to the World of VBA
Home > VBAUsefulCodes

Selecting file or folder with Browse File Option


Selecting file or folder with Browse File Option with VBA

' To Select File 

sub select_file()
selected_file = Application.GetOpenFilename(, , "Select File", , False)
End sub

' To Select Folder

Sub selectfolder()

zhr_folder = GetFolder()

End sub

 

Function GetFolder() As String

Dim fldr As FileDialog

Dim sItem As String

Set fldr = Application.FileDialog(msoFileDialogFolderPicker)

With fldr

    .Title = "Select a Folder"

    .AllowMultiSelect = False

    .InitialFileName = ""

    If .Show <> -1 Then GoTo NextCode

    sItem = .SelectedItems(1)

End With

NextCode:

GetFolder = sItem

Set fldr = Nothing

End Function

Subscribe

Enter your e-mail below and get notified on the latest blog posts.




Tags

VBA Outlook KPI Excel Alt+F11 Dashboards Macros Recording Graphs Automation Developer WaterFall Powerpoint Charts Pivot Tables Forecast Charts


Follow Us