View Full Version : giving a direction to VBA to open a specific file
an89as
12-28-2021, 11:30 AM
Hello Everyone,
I would appreciate if someone guide me to code a direction to VBA excel to open a file in specific file within my computer.
Please make it simple as I am a beginner in the VBA.
Thanks in advance!
arnelgp
12-28-2021, 08:16 PM
here is a sample:
Private Sub test2()
Dim strFile As String
With Application.FileDialog(msoFileDialogFilePicker)
'Makes sure the user can select only one file
.AllowMultiSelect = False
'Filter to just the following types of files to narrow down selection options
.Filters.Add "All Files", "*.*", 1
'Show the dialog box
.Show
'Store in fullpath variable
strFile = .SelectedItems.Item(1)
'if a file is selected then Open it
If Len(strFile) <> 0 Then
CreateObject("Shell.Application").ShellExecute strFile, "", "", "Open"
End If
End With
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.