Help With Excel Object Library - Worksheet & Range

Mfrosty

New Member
Joined
May 23, 2012
Messages
15
Hey guys,

Not really familiar with the excel object library so I am struggling with some basic syntax that I hope is a quick fix and a "Doh!" moment.


Goal: Take my 10 worksheets that have a mix of charts/text/images but in the ranges of A1:O37 in an excel workbook and dump each one into its own powerpoint slide. Seems simple enough right? I bolded the parts where I think my problems are.

Here is my code:

Code:
Sub ExceltoPPT()

        Dim newPPT As PowerPoint.Application
        Dim slidePPT As PowerPoint.Slide
[SIZE=3][B]        Dim sheetXLS As Excel.Worksheet[/B][/SIZE]
     
        On Error Resume Next
        Set newPPT = GetObject(, "PowerPoint.Application")
        On Error GoTo 0
     
        If newPPT Is Nothing Then
            Set newPPT = New PowerPoint.Application
        End If


        If newPPT.Presentations.Count = 0 Then
            newPPT.Presentations.Add
        End If
     


        newPPT.Visible = True
    
[U]    'This is where I want it to go through each worksheet & copy the range A1:O37. Should the syntax be something like ActiveSheet.xxx?[/U]
        For Each sheetXLS In Range("A1:O37")
        
        'Adds a new slide for each worksheet found
            newPPT.ActivePresentation.Slides.Add newPPT.ActivePresentation.Slides.Count + 1, ppLayoutText
            newPPT.ActiveWindow.View.GotoSlide newPPT.ActivePresentation.Slides.Count
            Set slidePPT = newPPT.ActivePresentation.Slides(newPPT.ActivePresentation.Slides.Count)
                
[U]        'Worksheet gets copied hopefully. What do I put for the spot I bolded? Name of file or each worksheet?[/U]
[SIZE=3][B]            Page1xls.Select[/B][/SIZE]
            ActiveChart.ChartArea.Copy
            slidePPT.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
    
        newPPT.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
        newPPT.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True


        Next
     
    AppActivate ("Microsoft PowerPoint")
    Set slidePPT = Nothing
    Set newPPT = Nothing
     
End Sub

Any help would be greatly appreciated. I am sure with enough trial and error I will figure it out regardless. thanks!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,215,780
Messages
6,126,857
Members
449,345
Latest member
CharlieDP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top