Need help to access and loop between objects in two applications (Excel & PowerPoint)

Respondido Need help to access and loop between objects in two applications (Excel & PowerPoint)

  • Montag, 20. August 2012 20:18
     
     

    The code below resides in a PowerPoint VBE.  I want to write the resslidearray, which contains the SlideIDs for each of the slides in my presentation, to an Excel sheet.  As you can see, I'm accessing Excel by "AppActivate Title", but I need to know how to access PowerPoint's resslidearray to write it to Excel.  Essentially, the loop is looping between Excel and PowerPoint, but I haven't figured out how to make it work. I'm very new to writing VBA to access outside applications, so any adivce is appreciated. Thank you!

       
        Set xlApp = New Excel.Application
        xlApp.Visible = True
        Set xlBook = xlApp.Workbooks.Add
       
    'writes resslidearray to excel sheet
        Title = xlApp.Caption
            For i = 1 To ActivePresentation.Slides.Count
                AppActivate Title
                ActiveSheet.Range("Ai") = resslidearray(i)
            Next i

Alle Antworten

  • Dienstag, 21. August 2012 07:32
    Beantworter
     
     Beantwortet Enthält Code
    Sub MyMacroo()
        Dim xlApp As Object, xlBook As Object
        Dim i As Long
        
        Set xlApp = CreateObject("Excel.Application")
        Set xlBook = xlApp.Workbooks.Add
            
        'writes resslidearray to excel sheet
        
        For i = 1 To ActivePresentation.Slides.Count
              xlApp.Range("A" & i) = resslidearray(i)
        Next i
        
        xlApp.Visible = True
    End Sub
    See if it helps.

    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    • Als Antwort vorgeschlagen VBAToolsMVP, Editor Dienstag, 21. August 2012 14:41
    • Als Antwort markiert Looshsmoot Dienstag, 21. August 2012 17:53
    •  
  • Dienstag, 21. August 2012 14:41
    Beantworter
     
     

    Looshsmoot, Can you write resslidearray function?

    Without that procedure we cant classified as workin.


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

  • Dienstag, 21. August 2012 17:54
     
     

    Thank you.  This worked.

    Can you tell me why the New keyword does not work in this situation?

    Regards,

    Lucian

  • Mittwoch, 22. August 2012 06:41
    Beantworter
     
     

    I used CreateObject beauce if you use new then you must add reference to Excel Object model.

    First add reference to Excel 12.0 Object Library then replace the line below 

    Set xlApp = CreateObject("Excel.Application")

    with

    Set xlApp =New Excel.Application


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.