• file open macro (word 2003)

    Author
    Topic
    #425551

    I have used a macro to open up the directory from which I want to get a file. It

    Viewing 0 reply threads
    Author
    Replies
    • #980710

      There seems to be something missing. You fill a variable strNewPath but you don’t do anything with it. Try this:

      If Not Right(strNewPath, 1) = “” Then
      strNewPath = strNewPath & “”
      End If

      With Dialogs(wdDialogFileOpen)
      .Name = strNewPath
      .Show
      End With

      • #980723

        it opens the correct dialog box, but when I select a file, it loads and I get a runtime error “5479”

        “you cannot close Microsoft Office Word because a dialog box is open. Click OK, switch to Word, and then close dialog box”

        • #980728

          Is there some other part of your code that tries to quit Word? The code as posted, with the modification I suggested, works fine in a test.

          • #980732

            I got the error message to go away, but now it keeps looping back and opening the dialog box after I open a file. Two escapes gets me back to the edit screen. Thanks for your time….

            Private Sub CommandButton1_Click()
            Unload Me
            End Sub

            Private Sub ListBox1_Click()
            ‘if a choice is clicked
            Dim strFirstLetter As String
            strFirstLetter = Left(Me.ListBox1.Value, 1)
            ShowOpenDialog strFirstLetter
            End Sub

            Private Sub ListBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
            ‘if a key is pressed
            ShowOpenDialog Chr(KeyAscii)
            End Sub

            Sub ShowOpenDialog(strLetter As String)
            ‘whether clicked or key-pressed, this sub shows the file open dialog
            strNewPath = “”
            Select Case strLetter
            Case “A”, “a”: strNewPath = “C:WP”
            Case “B”, “b”: strNewPath = “C:WPADMINISTRATION”
            Case “C”, “c”: strNewPath = “C:WPADDRESS”
            Case “D”, “d”: strNewPath = “C:WPMARKET”
            Case “E”, “e”: strNewPath = “C:WPMGP”
            Case “F”, “f”: strNewPath = “C:WPPROPOSAL”
            Case “G”, “g”: strNewPath = “C:WPCES”
            Case “H”, “h”: strNewPath = “C:!projects”
            Case “I”, “i”: strNewPath = “DjcDJShare”
            Case “J”, “j”: strNewPath = “c:!ona hearing data”
            Case “K”, “k”: strNewPath = “c:WPONA MINE”
            Case “L”, “l”: strNewPath = “c:!projects”
            Case “M”, “m”: strNewPath = “A:”
            Case “N”, “n”: strNewPath = “D:”
            End Select

            If Not Right(strNewPath, 1) = “” Then
            strNewPath = strNewPath & “”
            End If

            With Dialogs(wdDialogFileOpen)
            .Name = strNewPath
            .Show
            End With

            End Sub
            Private Sub UserForm_Initialize()
            Me.CommandButton1.Cancel = True
            Me.CommandButton1.Caption = “Cancel”
            With Me.ListBox1
            .AddItem “A C:WP”
            .AddItem “B C:WPADMINISTRATION”
            .AddItem “C C:WPADDRESS”
            .AddItem “D C:WPMARKET”
            .AddItem “E C:WPMGP”
            .AddItem “F C:WPPROPOSAL”
            .AddItem “G C:WPCES”
            .AddItem “H C:projects”
            .AddItem “I Dj(2) c:DJShare”
            .AddItem “J c:!ona hearing data”
            .AddItem “K c:wpona mine”
            .AddItem “L c:!projects”
            .AddItem “M A:”
            .AddItem “N D:”
            .SetFocus
            End With
            End Sub

            • #980733

              This time, you have omitted the line

              Unload Me

              from ShowOpenDialog (it must come somewhere after End Select).

            • #980735

              it works! it works!

              Thanks!

    Viewing 0 reply threads
    Reply To: Reply #980710 in file open macro (word 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel