+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    06-30-2009
    Location
    Southern California, Earth
    MS-Off Ver
    Excel 2003
    Posts
    71

    Cool GetOpenFilename error with spaces in file

    I'm not sure why but the following code results in an error when the file you point to includes spaces. It works fine otherwise.

    Any thoughts? I'm thinking maybe I can replace the spaces with nil?


    Code:
         Filename = Application.GetOpenFilename("Adobe PDF (*.pdf),*.pdf")
         
         destinLOC = Filename
         destinLOC = Replace(destinLOC, "pdf", "txt")
         
         destinPLN = Right(Filename, Len(Filename) - InStrRev(Filename, "\"))
         destinPLN = Replace(destinPLN, ".pdf", "")
         
         destinTXT = Right(Filename, Len(Filename) - InStrRev(Filename, "\"))
         destinTXT = Replace(destinTXT, "pdf", "txt")
         
         taskid = Shell("C:\pdf\pdftotext.exe " & Chr(34) & Filename & Chr(34) & " " & destinTXT, vbNormalFocus)
                 
         WAIT = Timer
         While Timer < WAIT + 2
            DoEvents  'do nothing
         Wend
         
         'Importation
         'destinTXT is the source below for some unexplained reason :)
         Workbooks.OpenText Filename:=destinTXT, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
            ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _
            Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _
            , 1)), TrailingMinusNumbers:=True
    This is the result of the debug immediately after the bolded line above..

    Code:
    Debug.Print destinTXT
    Jun 09 PSR Lvl 2.txt
    Debug.Print destinLOC
    C:\Jun 09 PSR Lvl 2.txt
    debug.Print destinPLN
    Jun 09 PSR Lvl 2
    The error is occurring during the Workbooks.OpenText event. I'm assuming it has to do with passing the wrong arguments to the Shell event in which case there is nothing for it to open. Actually, I'm certain that is what is happening.

    Any thoughts or ideas are greatly appreciated! Thanks in advance..
    Last edited by hoffey; 07-20-2009 at 03:30 PM.

  2. #2
    Registered User
    Join Date
    06-30-2009
    Location
    Southern California, Earth
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: GetOpenFilename error with spaces in file

    This fixed it.. Sorry for the post! I guess sometimes you just have to ask the question..

    Code:
         destinLOC = Filename
         destinLOC = Replace(destinLOC, "pdf", "txt")
        
         destinPLN = Right(Filename, Len(Filename) - InStrRev(Filename, "\"))
         destinPLN = Replace(destinPLN, ".pdf", "")
         destinPLN = Replace(destinPLN, " ", "")
        
         destinTXT = Right(Filename, Len(Filename) - InStrRev(Filename, "\"))
         destinTXT = Replace(destinTXT, "pdf", "txt")
         destinTXT = Replace(destinTXT, " ", "")

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0