Consulting

Results 1 to 7 of 7

Thread: PPT VBA to Insert Slides via ReUse Slides

  1. #1

    PPT VBA to Insert Slides via ReUse Slides

    I have some code that is giving me a RUn time Error: Slides (unknown member): Failed

    It happens on this line:
    ActivePresentation.Slides.InsertFromFile _FileDownload, 1, 1, 26


    Sub Finish()
    
    
    Dim URL1 As String
    Dim URL2 As String
    Dim TextFile As Integer
    Dim FilePath As String
    Dim FileContent As String
    Dim FileDownload As String
    Dim i As Long
    
    
    'PURPOSE: Send All Data From Text File To A String Variable
    
    
    'File Path of Text File
      FilePath = GetDownloadsPath & "\" & "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
      
    FileDownload = GetDownloadsPath & "\" & FileContent & ".pptx"
    
    
    ActivePresentation.Slides.InsertFromFile _
    FileDownload, 1, 1, 26
        
        'Delete Text File
        Kill FileDownload
    End Sub

    Any ideas how to correct?

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,014
    Location
    What is the GetDownloadPath ??
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Sorry about that John...

    Function GetDownloadsPath() As String

    GetDownloadsPath = Environ$("USERPROFILE") & "\Downloads"


    End Function

  4. #4
    Quote Originally Posted by John Wilson View Post
    What is the GetDownloadPath ??
    John,

    Here is the GetDownloadsPath Function:

    Function GetDownloadsPath() As String
        
        GetDownloadsPath = Environ$("USERPROFILE") & "\Downloads"
    
    
    End Function
    I did just discover if I replace FileDownload from ActivePresentation.Slides.InsertFromFile FileDownload, 1, 1, 26 with the actual hard coded file path and name the error goes away so know I think I have a problem with my GetDownloadsPath?

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,014
    Location
    The only thing that jumps out as a possible problem.

    Where you say 'Delete Text File
    You are actually deleting the pptx I think. Maybe it is being killed before it has fully reused the slides. I'm presuming there are 26 slides to insert.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    I have commented out the Delete Text File and I still have the issue. If I debug and hover over

    FileContent = Input(LOF(TextFile), TextFile)
    I get FileContent = "Category Review Grand Canyon - Packaged Beverages. Notice the leading quote but no ending quote. However, if I open the immediate window and do ? FileContent I get Category Review Grand Canyon - Packaged Beverages without any quotes.

    Could this be the issue?

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,014
    Location
    Are you sure that is the Downloads folder??

    For me it's
    getDownloadsPath = Environ("USERPROFILE") & "\Documents\Downloads"

    Apart from that the code works for me but of course I cannot see what you have in the text file. Are there quotes there?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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