Consulting

Results 1 to 2 of 2

Thread: giving a direction to VBA to open a specific file

  1. #1
    VBAX Newbie
    Joined
    Dec 2021
    Posts
    1
    Location

    Post giving a direction to VBA to open a specific file

    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!

  2. #2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •