+ Reply to Thread
Results 1 to 15 of 15

Method 'Open' of object 'Presentations' failed when running a VBA loop

  1. #1
    Registered User
    Join Date
    06-20-2016
    Location
    Sweden
    MS-Off Ver
    Windows 7
    Posts
    13

    Method 'Open' of object 'Presentations' failed when running a VBA loop

    Hello Excel Gurus,

    This is the first time I am trying to make a VBA macro which generates PDF presentations automatically, so I am a newbie to this. It works to run once, but I get an error message when the macro runs a second time in a loop.

    I get the following two error messages:
    - Method 'Open' of object 'Presentations' failed
    - The remote server machine does not exist or is unavailable (run-time error '462')

    I have Googled around a bit to figure out what the issue is, but not found a solution which I fully understand, i.e. I still do not know what is missing in my code.

    I am using the below code:

    PHP Code: 
    Sub generateReport()
          
        
    Dim PPT As PowerPoint.Application
        Set PPT 
    = New PowerPoint.Application
        PPT
    .Visible True
        
        Dim objReport 
    As Presentation
        Dim objSlide 
    As Slide
        Dim objShape 
    As Object
         
        excelPath 
    Application.ActiveWorkbook.Path
        pptTemplateName 
    "Report.pptx"
        
        'THIS IS WHERE THE ERROR APPEARS IN THE SECOND LOOP'
        
    Set objReport PPT.Presentations.Open(Filename:=excelPath "\" & pptTemplateName)    
        
        'Defining presentation version'
        versionNumber = Sheets("
    Analysis").Range("D4").Value 

        'Inputting text to presentation from Excel'
        Dim i As Integer
        
        firstInputRow = 38
        inputLength = Sheets("
    Analysis").Range("D" & firstInputRow - 3).Value
        
        For i = 1 To inputLength
        
            slideNum = Sheets("
    Analysis").Range("B" & firstInputRow + i - 1).Value
            boxName = Sheets("
    Analysis").Range("C" & firstInputRow + i - 1).Value
            textInput = Sheets("
    Analysis").Range("D" & firstInputRow + i - 1).Value
          
            Set objSlide = objReport.Slides(slideNum)
            objSlide.Shapes(boxName).TextFrame.TextRange.Text = textInput
      
        Next i

        'Updating charts in presentation'
        inputLength = Sheets("
    Analysis").Range("J" & firstInputRow - 3).Value
          
        For i = 1 To inputLength
        
            slideNum = Sheets("
    Analysis").Range("I" & firstInputRow + i - 1).Value
            boxName = Sheets("
    Analysis").Range("J" & firstInputRow + i - 1).Value
            objReport.Slides(slideNum).Shapes(boxName).LinkFormat.Update
          
        Next i
        
        'Saving presentation as PDF'
        FileName2 = Replace(excelPath & "
    \" & versionNumber & " " & pptTemplateName, "pptx", "pdf")
        
        objReport.SaveAs FileName2, ppSaveAsPDF
        objReport.Close

        Set objShape = Nothing
        Set objSlide = Nothing
        Set objReport = Nothing
        
        PPT.Quit
        Set PPT = Nothing
        
    End Sub 

    Any help would be greatly appreciated.
    Last edited by apantorsk; 06-20-2016 at 09:08 AM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    Welcome to the forum!

    Maybe replace the Close line with:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-20-2016
    Location
    Sweden
    MS-Off Ver
    Windows 7
    Posts
    13

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    Hi Kenneth,

    Thank you for your reply. I appreciate it.

    I replaced the following code:
    Please Login or Register  to view this content.
    with the following code:
    Please Login or Register  to view this content.
    This did not solve the issue, and I still get the same error messages on the second loop.

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    On your 2nd run, run by pressing F8 at each line. Then you can see where it goes amiss.

  5. #5
    Registered User
    Join Date
    06-20-2016
    Location
    Sweden
    MS-Off Ver
    Windows 7
    Posts
    13

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    I did this and I got a surprising result. I scanned through by slowly running the code, line by line, and this way I ran through the whole code without a problem.

    But when I run the code without breaks I get the same error as before on this line when running the second loop:

    Please Login or Register  to view this content.
    The same happens when I run the code with a break on that line.

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    After the 1st run, Alt+Ctrl+Del > Task Manager. Look for an open instance of the file. IF there, delete it (right click and stop the task) and try the 2nd run. I suspect that it is leaving an instance open.

  7. #7
    Registered User
    Join Date
    06-20-2016
    Location
    Sweden
    MS-Off Ver
    Windows 7
    Posts
    13

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    Thank you for the suggestion. How do I look for an open instance of the file?

    Unfortunately my VBA skills are on a quite low level, especially when it comes to PPT connections.

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    That is a Windows thing. It is often referred to as the 3 finger salute. For more detail see: https://technet.microsoft.com/en-us/...(v=ws.11).aspx

    It is an easy way to see if you have an orphan task like the ppt file still open. Setting your object to Nothing should fix that. Howsoever, when it errors, setting those will not happen. You need an Error catching routine.

    e.g.
    Please Login or Register  to view this content.
    Of course you may want a 2nd Goto so that you can skip a MsgBox that shows that an error occurred.

    Example error handling:
    Please Login or Register  to view this content.
    Last edited by Kenneth Hobson; 06-20-2016 at 12:12 PM.

  9. #9
    Registered User
    Join Date
    06-20-2016
    Location
    Sweden
    MS-Off Ver
    Windows 7
    Posts
    13

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    What is happening now is that the Macro only generates the first report, and does not generate the reports in the second, third (etc.) loops.

    As per your suggestion my code now looks like this:

    Please Login or Register  to view this content.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    Are you calling this sub from a loop in another sub?

    Does this work any better?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  11. #11
    Registered User
    Join Date
    06-20-2016
    Location
    Sweden
    MS-Off Ver
    Windows 7
    Posts
    13

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    A tweaked version of your suggestion worked. I think one of the issues was that I had not defined all variables.

    One issue I have now is that I can run the code line by line, but when I run the whole code - which should generate e.g. 20 different presentations, it sometimes stops in the middle of the code and generates an error.

    I'm not sure if error handling is the issue, but is seems weird to me that the code works fine line by line, but sometimes stops in the middle when i run long loops. Could it have to do with the amount of memory my excel can handle? Any solutions to this?

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    How are you running the code multiple times?

    Within a loop?

    Calling it from within a loop in another sub?

  13. #13
    Registered User
    Join Date
    06-20-2016
    Location
    Sweden
    MS-Off Ver
    Windows 7
    Posts
    13

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    I do this within a loop.

    The algorithm is as follows:
    1. Open PPT
    2. Enter loop
    3. Insert text and update charts
    4. Create PDF of current version of PPT
    5. Next iteration in the loop

  14. #14
    Registered User
    Join Date
    06-20-2016
    Location
    Sweden
    MS-Off Ver
    Windows 7
    Posts
    13

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    VBA sometimes gives me an error after a couple of loops. I'm thinking an issues could be that the code is taking to much processor memory when opening, saving an closing several PPTs and PDFs. Could a solution be to build in 1 sec stops as the code runs?

  15. #15
    Registered User
    Join Date
    06-20-2016
    Location
    Sweden
    MS-Off Ver
    Windows 7
    Posts
    13

    Re: Method 'Open' of object 'Presentations' failed when running a VBA loop

    I solved this by building in an error handler which pauses the program for 3 sec and then reruns the loop.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Method 'Open of object 'Workbooks'Failed
    By elmnas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2015, 07:40 PM
  2. [SOLVED] method 'open text' of object 'workbooks' failed
    By tina in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-23-2013, 11:53 AM
  3. method 'open text' of object 'workbooks' failed
    By richieniel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2013, 10:42 AM
  4. [SOLVED] Method 'open' of object 'workbooks' failed
    By crunchKH in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-01-2013, 09:13 PM
  5. [SOLVED] Method 'Range' of object '_Global' failed error message on running userform when another
    By sivakumar123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-01-2012, 11:39 AM
  6. Open method of object failed error
    By maw230 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2011, 09:19 AM
  7. Method 'Open' of object 'Workbooks' failed from within browser window
    By ramiro in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-07-2008, 12:08 AM

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