Using the dot operator we can see and use the IntelliSense properties of the object.
VBA DETERMINE FILE TYPE CODE
We do not need to specify the path to code using this object.FileDialog is an object property of VBA.Step 8: Give a file name and press Save it will give us the Path for the file as follows. Step 7: Now execute the above code and see the result, it opens a dialog box to save the file. Step 6: Now let us display the result using the msgbox function and end the IF Loop. Path = Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1) Step 5: Now let us get the path selected by the user in our path variable as follows. Step 4: Now use IF statement to determine the choice of the user as follows. Step 3: Now let us make the dialog box visible to the user using the show property as follows.Ĭhoice = Application.FileDialog(msoFileDialogSaveAs).Show Step 2: Now declare two variables one as string while another as an integer.ĭim Choice As Integer, Path As String End Sub Step 1: In the same module let us write another sub procedure to save the file as follows. Follow the below steps to use excel VBA FileDialog. This property is used to save a file on any path. Now let us see another option of the VBA FileDialog object which is msoFileDialogSaveAs. Step 16: Let us execute the above code and select a file and press ok to see the path as follows. Step 15: After the With Statement use the msgbox function to display the address of the file selected. Step 14: We will use a selecteditems statement to find the path for the of the file user selected and store it in our variable as follows. Step 13: Since we need to display the user path selected, declare another variable as a string in the code.ĭim Path As String Set File = Application.FileDialog(msoFileDialogFilePicker) Step 12: Once we execute the above code we can see the dialog box as follows. Step 11: Now in order to show the dialog box we can write. AllowMultiSelect = False End With End Sub Step 10: Now do we want the user to select multiple files at once or a single file? For this example let us stick with the single file at a time, so use. Step 9: If there are any filters we need to clear the filters, put a dot statement and write the statement as shown below. Step 8: Now we need to make the dialog box for this example, let us use With Statement as follows. Set File = Application.FileDialog(msoFileDialogFilePicker) Step 7: Select the option of Filedialog type as msoFileDialogFilePicker Step 6: Once we open the parenthesis we can see the option for four FileDialog types as shown in the image below. Step 5: Now let us use this object from the Application.Filedialog method as follows. Step 4: Declare a variable as Filedialog as shown below. Step 3: Start the subprocedure to start working on example. Step 2: Open a Module from the Insert menu option as shown below. Step 1: Go to the Developers tab and click on Visual Basic. Follow the below steps to use excel VBA FileDialog: