Consulting

Results 1 to 8 of 8

Thread: Carriage Return

  1. #1

    Carriage Return

    Hello,

    I am getting a carriage return that is preventing the last line of code here from firing

    Sub BuildPPT()
    
        Dim FilePath        As String
        Dim TextFile        As Integer
        Dim FileContent     As String
        Dim URL1            As String
        Dim URL2            As String
        Dim varrPos         As Variant
        Dim i               As Long
        Dim pptStrFile      As String
    
    
        'File Path & Name of Text File
        FilePath = GetDownloadPath & "Category Review BUCategory.txt"
        
        'Determine the next file number available for use by the FileOpen function
        TextFile = FreeFile
        
        'Open the text file
        Open FilePath For Input As TextFile
        
        'Store file content inside a variable
        FileContent = Input(LOF(TextFile), TextFile)
        
        
        'Close Text File
        Close TextFile
        
        pptStrFile = Trim(GetDownloadPath) & Trim(FileContent)
        pptStrFile = Trim(Replace(pptStrFile, vbCr, ""))
        
        ActivePresentation.Slides.InsertFromFile pptStrFile, 1, 1, 26
    The value of pptStrFile should be:


    C:\Users\mogr0002\Downloads\Category Review Grand Canyon - Packaged Beverages.pptx

    The immediate window for ? pptStrFile returns the value I am looking for but then adds another blank line below it which I don't why and that is preventing the last line of the code from working.

    The text that is in the text file that is being read is:

    Category Review Grand Canyon - Packaged Beverages.pptx


    Any thoughts?

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
        'File Path & Name of Text File
        FilePath = GetDownloadPath & "Category Review BUCategory.txt"
        
        'Determine the next file number available for use by the FileOpen function
        TextFile = FreeFile
        
        'Open the text file
        Open FilePath For Input As TextFile
        
        'Store file content inside a variable
        FileContent = Input(LOF(TextFile), TextFile)
    
    MSgBox FileContent
    MsgBox GetDownloadPath
    '
    '
    '
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    SamT

    MsgBox FileContent = Category Review Grand Canyon - Packaged Beverages.pptx
    MsgBox GetDownloadPath = C:\Users\mogr0002\Downloads\

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    I would input by Line and check for blank lines ( They are probably in the textfile)
    Sub getFC()
    Dim filenum As Integer
    Dim buffer As String
    Dim filepath As String
    Dim FileContent As String
    'use your path of course
    filepath = "C:\Users\Info\Desktop\test.txt"
    filenum = FreeFile
    Open filepath For Input As filenum
        'Store file content inside a variable
    While Not EOF(filenum)
    Line Input #filenum, buffer
    ' ignore blank line
    If Not Trim(buffer) = "" Then
    FileContent = buffer
    End If
    Wend
        Debug.Print FileContent
    End Sub
    Last edited by John Wilson; 06-22-2021 at 01:41 PM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    John Wilson,

    I ran your code and it doesn't look like I have blank lines that show in the immediate window now? Was this code supposed to remove any blank lines and if so, I should input this code into my existing code to remove the blank lines?

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Inspect "Category Review BUCategory.txt" in Notepad. Especially look for VbCrs and extra spaces at either end of lines and in any blank lines

    Also

    Inspect "Category Review BUCategory.txt" in Word. Especially look for VbCrs and extra spaces at either end of lines and in any blank lines


    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    My code reads the text file line by line till End Of File (EOF) it would ignore any blank line and is an alternative to the Lentgh Of File method you used which will not ignore blank lines. AS both Sam and I have said the blank line (maybe just a carriage return) if probably in the text file itself and the best answer would be to remove it
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Try
    FileContent = Input(LOF(TextFile)-3, TextFile)
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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