Share via

Listened to Co Pilot

SteveD 435 Reputation points
2026-04-05T04:25:19.53+00:00

Hello from Steve

Now all I need please is to open

Sub OpenForm2()

Const strFolder As String = "C:\Tab Form\Input Stakes"

Dim doc As Document

With Application.FileDialog(FileDialogType:=1) ' 1 = msoFileDialogOpen

    .Filters.Clear

    .Filters.Add Description:="Word documents (*.doc*)", Extensions:="*.doc*"

    .InitialFileName = strFolder & "*.doc*"

    If .Show Then

        Set doc = Documents.Open(FileName:=.SelectedItems(1))

    Else

        Beep

        Exit Sub

    End If

End With
End Sub

Mod moved from : Microsoft 365 and Office | Word | For home | Windows

Developer technologies | Visual Basic for Applications
0 comments No comments

2 answers

Sort by: Most helpful
  1. Nancy Vo (WICLOUD CORPORATION) 4,030 Reputation points Microsoft External Staff Moderator
    2026-04-22T04:01:41.2133333+00:00

    Hello @SteveD ,

    Thanks for your question.

    I see one small issue with the InitialFileName line. The folder path is missing a backslash () before the wildcard, which can cause the initial folder to not resolve properly. I recommend these following code:

    Sub OpenForm2()
        Const strFolder As String = "C:\Tab Form\Input Stakes\"
    
        Dim doc As Document
    
        With Application.FileDialog(FileDialogType:=1) ' 1 = msoFileDialogOpen
    
            .Filters.Clear
            .Filters.Add Description:="Word documents (*.doc*)", Extensions:="*.doc*"
            .InitialFileName = strFolder & "*.doc*"
    
            If .Show Then
                Set doc = Documents.Open(FileName:=.SelectedItems(1))
            Else
                Beep
                Exit Sub
            End If
    
        End With
    End Sub
    

    Please try and let me know if it works.

    I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.

    Was this answer helpful?

    1 person found this answer helpful.

  2. Q&A Assist
    2026-04-05T04:25:30.4633333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Use the Documents.Open method with the file path returned by the FileDialog, as in the sample below. The main change is to ensure the InitialFileName ends with a backslash and to keep the Open call simple:

    Sub OpenForm2()
    
        Const strFolder As String = "C:\Tab Form\Input Stakes\"  ' note trailing backslash
        Dim doc As Document
    
        With Application.FileDialog(FileDialogType:=1) ' 1 = msoFileDialogOpen
            .Filters.Clear
            .Filters.Add Description:="Word documents (*.doc*)", Extensions:="*.doc*"
            .InitialFileName = strFolder
    
            If .Show Then
                Set doc = Documents.Open(FileName:=.SelectedItems(1))
            Else
                Beep
                Exit Sub
            End If
        End With
    
    End Sub
    

    This code:

    • Opens a File Open dialog in C:\Tab Form\Input Stakes\.
    • Filters to show only Word documents (*.doc*).
    • Opens the selected file into a Document object using Documents.Open.

    If needed, the opened document can then be manipulated via the doc variable (for example, doc.Save, doc.Close, etc.).


    References:

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.