+ Reply to Thread
Results 1 to 4 of 4

Hidden String

Hybrid View

  1. #1
    Registered User
    Join Date
    06-30-2009
    Location
    Southern California, Earth
    MS-Off Ver
    Excel 2010
    Posts
    72

    Cool Hidden String

         destinLOC = Filename
         MsgBox destinLOC
         destinLOC = WorksheetFunction.Substitute(Instring, "pdf", "txt")
         MsgBox destinLOC
    Not sure why, but after the first MsgBox I can clearly see the location of the file, but as soon as I run the Substitute function, it shows up in the second MsgBox empty.

    Any ideas? Thanks in advance...
    Last edited by hoffey; 07-14-2009 at 08:55 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Hidden String

    What is Instring?

    Once you get that sorted, you can use the VBA native Replace function instead of WF.Substitute.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    06-30-2009
    Location
    Southern California, Earth
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: Hidden String

    Thanks for the reply SHG. Yes, I'm new to VBA so sometimes the first solution I come across is nowhere near ideal.


    Sub PdFN()
    
    Dim taskid As Double
    Dim sourcePDF As String
    Dim destinTXT As String
    Dim Filename As String
    
         Filename = Application.GetOpenFilename("Adobe PDF (*.pdf),*.pdf")
        
         destinLOC = Filename
         destinLOC = Replace(destinLOC, "pdf", "txt")
        
         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)
        
         'Importation
         Workbooks.OpenText Filename:=destinLOC, 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
       
        Columns("A:AH").Select
        Columns("A:AH").EntireColumn.AutoFit
        ActiveWindow.LargeScroll ToRight:=-1
        Range("A1").Select
    
    End Sub
    Changing to Replace did the trick, now however it is not opening correctly. I'm getting a 1004 error in the bolded area. Is there a better way to open the file?

    Thanks in advance..

  4. #4
    Registered User
    Join Date
    06-30-2009
    Location
    Southern California, Earth
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: Hidden String

    Changed destinLOC with destinTXT and it worked, I thought it would be the other way around. hmmm

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1