Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    May 2002
    Posts
    410
    Thanks
    1
    Thanked 0 Times in 0 Posts

    file open macro (word 2003)

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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: file open macro (word 2003)

    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

  3. #3
    4 Star Lounger
    Join Date
    May 2002
    Posts
    410
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: file open macro (word 2003)

    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"

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: file open macro (word 2003)

    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.

  5. #5
    4 Star Lounger
    Join Date
    May 2002
    Posts
    410
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: file open macro (word 2003)

    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 Crojects"
    .AddItem "I Dj(2) cJShare"
    .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

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: file open macro (word 2003)

    This time, you have omitted the line

    Unload Me

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

  7. #7
    4 Star Lounger
    Join Date
    May 2002
    Posts
    410
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: file open macro (word 2003)

    it works! it works!

    Thanks!

Posting Permissions

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