VBA - Open a file with Shell if the filename contains a blank?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OldBirdman
    Contributor
    • Mar 2007
    • 675

    #1

    VBA - Open a file with Shell if the filename contains a blank?

    I want to open a file in WordPad from Access. This code works correctly.
    Code:
    Private Sub cmdOpenRTF_Click()
    Dim stAppName As String
        stAppName = "C:\Program Files\Windows NT\Accessories\WordPad.exe " & "D:\Convert\Convert.rtf"
        Call Shell(stAppName, vbNormalFocus)
    End Sub
    However, if the filename (or folder name) contains a blank, I get the non-trappable error "Failed to open document." No message number.
    How can I open a file with Shell if the filename contains a blank?
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    Use the double-quotes format OB.
    Code:
    stAppName = "My silly space filled filename.Blx"
    stAppName = "C:\Program Files\Windows NT\Accessories\WordPad.exe """ & stAppName & """"

    Comment

    • OldBirdman
      Contributor
      • Mar 2007
      • 675

      #3
      Why didn't I think of that? So obvious. Thank you:)

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        It's always a special pleasure to be able to help one of our Experts OB (whatever your tag says ;) ).

        Comment

        Working...