I am trying to prepare a presentation from Excel. As of now VBA code is preparing "n number of "presentations as per no of times Loop runs. I want Code to generate just 1 presentation with all slides combined. Fist Macro "Addnumber" is run, which run Macro "ExcelRangeToPowerPoint". Its Macro "ExcelRangeToPowerPoint"which need to add slides for every loop of Macro "Addnumber"
Please Support
Sub AddNumber()
Dim Ws As Worksheet
Dim rngSel As Range
Dim rng As Range
Dim Num As Double
Dim i As Long
Dim j As Long
Dim lAreas As Long
Dim lRows As Long
Dim lCols As Long
Dim Arr() As Variant
Set rngSel = Worksheets("Sheet1").Range("A5:A30")
Do Until Range("A30") = Range("A3")
Num = 26
For Each rng In rngSel.Areas
If rng.Count = 1 Then
rng = rng + Num
Else
lRows = rng.Rows.Count
lCols = rng.Columns.Count
Arr = rng
For i = 1 To lRows
For j = 1 To lCols
Arr(i, j) = Arr(i, j) + Num
Next j
Next i
rng.Value = Arr
End If
Call ExcelRangeToPowerPoint
Next rng
Loop
End Sub
Sub ExcelRangeToPowerPoint()
'PURPOSE: Copy/Paste An Excel Range Into a New PowerPoint Presentation
Dim rng As Range
Dim rng2 As Range
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim myShape As Object
Dim mySize As PageSetup
Dim Addtitle As Shape
Dim DateT As String
'Copy Range from Excel
Set rng = Worksheets("Sheet1").Range("E2:M30")
Set rng2 = Worksheets("Sheet1").Range("F2")
Set rng3 = Worksheets("Sheet1").Range("B3")
'Create an Instance of PowerPoint
On Error Resume Next
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")
'Clear the error between errors
Err.Clear
'If PowerPoint is not already open then open PowerPoint
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
'Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If
On Error GoTo 0
'Optimize Code
Application.ScreenUpdating = False
'Create a New Presentation
Set myPresentation = PowerPointApp.Presentations.Add
'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, 11)
'11 = ppLayoutTitleOnly
'Change Theme and Layout
mySlide.ApplyTheme "C:\Users\davinder.sond\AppData\Roaming\Microsoft\Templates\Document Themes\DefaultTheme.thmx"
myPresentation.PageSetup.SlideSize = 3
myPresentation.Slides(1).Shapes.Title.TextFrame.TextRange.Text = rng2
myPresentation.Slides(1).Shapes.Title.Left = 59
myPresentation.Slides(1).Shapes.Title.Top = 10
myPresentation.Slides(1).Shapes.Title.Height = 30
myPresentation.Slides(1).Shapes.Title.Width = 673
With myPresentation.Slides(1).Shapes.Title
With .TextFrame.TextRange.Font
.Size = 24
.Name = "Arial"
.Bold = True
.Color.RGB = RGB(255, 255, 255)
End With
End With
'Copy Excel Range
rng.Copy
'Paste to PowerPoint and position
mySlide.Shapes.PasteSpecial DataType:=2 '2 = ppPasteEnhancedMetafile
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
'Set position:
myShape.LockAspectRatio = 0
myShape.Left = 12
myShape.Top = 55
myShape.Height = 475
myShape.Width = 756
'Make PowerPoint Visible and Active
PowerPointApp.Visible = True
PowerPointApp.Activate
DateT = Format("h:mm:ss")
'Clear The Clipboard
Application.CutCopyMode = False
myPresentation.SaveAs "C:\Project Control CCJV\ExperimentsPunch\" & rng3 & ".pptm"
PowerPointApp.Quit
End Sub
You are creating a new presentation everytime you call Set myPresentation = PowerPointApp.Presentations.Add within ExcelRangeToPowerPoint().
You can either try to open/close the Presentation outside of ExcelRangeToPowerPoint() and add a parameter to the function like ExcelRangeToPowerPoint(myPresentationObject) then you can simple add the slides there
or
you call the function AddNumber() within ExcelRangeToPowerPoint() of coarse the you need to loop there...
e.g.
Sub ExcelRangeToPowerPoint()
' some preparative code
'Create a New Presentation
Set myPresentation = PowerPointApp.Presentations.Add
'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, 11)
For Each rng in rngSel.Areas
'Filling the presentation one slide at a time
AddSlide(rng)
Next
'Clear The Clipboard
Application.CutCopyMode = False
myPresentation.SaveAs "C:\Project Control CCJV\ExperimentsPunch\" & rng3 &
".pptm"
PowerPointApp.Quit
'some more code
End Sub
Related
I have a data set that Im trying to tur into automatic PowerPoint slides.The number of rows changes weekly so the range has to be variable.
this is how my data looks like
So far i've been able to create a slide for each title, copy the headers as an image and add copy the value of the 16th cell to each slide, but now i want to copy the values of each row its looping as an image but only from columns B to O.
So that the First slide would have (B1:O1)
The second would have (B2:O2)
But i haven figured out how to do it.
I wanted to use "rowShape" as the name for the rows image
Here's my code so far:
Option Explicit
Sub Data_to_PowerPoint()
Dim newPowerPoint As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide
Dim ExcelRow As Range
Dim CellRange As Range
Dim SlideText As Variant
Dim lr As Long
Dim hdr As Range
Dim myShape As Object
Dim rowShape As Object
'The first range of cells in the table.
lr = Cells(Rows.Count, "A").End(xlUp).Row
Set CellRange = Sheets("TicketSummary").Range("A1:A" & lr)
'Determine header range.
Set hdr = Sheets("TicketSummary").Range("B1:O1")
'Look for existing powerpoint instance
On Error Resume Next
Set newPowerPoint = GetObject(, "PowerPoint.Application")
On Error GoTo 0
'Create a PowerPoint
If newPowerPoint Is Nothing Then
Set newPowerPoint = New PowerPoint.Application
End If
'Setup the presentation in PowerPoint
If newPowerPoint.Presentations.Count = 0 Then
newPowerPoint.Presentations.Add
End If
'Make PowerPoint visible
newPowerPoint.Visible = True
'Loop through each chart in the Excel worksheet and paste them into the PowerPoint
For Each ExcelRow In CellRange
'Add a new slide
newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText
newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)
'Create the body text for the slide
SlideText = Cells(ExcelRow.Row, 16)
'Input the title of the slide
activeSlide.Shapes(1).TextFrame.TextRange.Text = ExcelRow.Value
'Input the body text for the slide
activeSlide.Shapes(2).TextFrame.TextRange.Text = SlideText
'Copy Header.
hdr.Copy
'Paste header to PowerPoint and position
activeSlide.Shapes.PasteSpecial DataType:=2 '2 = ppPasteEnhancedMetafile
Set myShape = activeSlide.Shapes(activeSlide.Shapes.Count)
'Set position:
myShape.Left = 60
myShape.Top = 152
Next
Set activeSlide = Nothing
Set newPowerPoint = Nothing
End Sub
Option Explicit
Sub Data_to_PowerPoint()
Dim pp As PowerPoint.Application, pps As PowerPoint.Slide
Dim lr As Long, i As Long, n As Long
'Look for existing powerpoint instance
On Error Resume Next
Set pp = GetObject(, "PowerPoint.Application")
On Error GoTo 0
'Create a PowerPoint
If pp Is Nothing Then
Set pp = New PowerPoint.Application
End If
'Setup the presentation in PowerPoint
If pp.Presentations.Count = 0 Then
pp.Presentations.Add
End If
'Make PowerPoint visible
pp.Visible = True
'The first range of cells in the table.
With Sheets("TicketSummary")
lr = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 2 To lr
' create slide
pp.ActivePresentation.Slides.Add i - 1, ppLayoutText
pp.ActiveWindow.View.GotoSlide i - 1
Set pps = pp.ActivePresentation.Slides(i - 1)
'Input the title of the slide
pps.Shapes(1).TextFrame.TextRange.Text = .Cells(i, "A")
'Input the body text for the slide
pps.Shapes(2).TextFrame.TextRange.Text = .Cells(i, "P") ' col 16
' copy header
' Paste to PowerPoint and position
' paste 2 = ppPasteEnhancedMetafile 3 ppPasteMetafilePicture
n = pps.Shapes.Count
.Range("B1:O1").Copy
Application.Wait Now + TimeSerial(0, 0, 1) ' 1 second wait
pps.Shapes.PasteSpecial DataType:=2
' wait for shape to be pasted
Do
DoEvents
Loop Until pps.Shapes.Count > n
Application.CutCopyMode = False
'Set position:
With pps.Shapes(n + 1)
.Left = 60
.Top = 182
End With
' copy row
n = pps.Shapes.Count
.Range("B1:O1").Offset(i - 1).Copy
Application.Wait Now + TimeSerial(0, 0, 1) ' 1 second wait
pps.Shapes.PasteSpecial DataType:=2
' wait for shape to be pasted
Do
DoEvents
Loop Until pps.Shapes.Count > n
Application.CutCopyMode = False
'Set position:
With pps.Shapes(n + 1)
.Left = 60
.Top = 202
End With
Next
End With
MsgBox lr - 1 & " slides created"
End Sub
I'm writing VBA program in powerpoint
The flow of program: VBA powerpoint macro have to open the excel file and copy and replace cell content to the specific shape in a specific slide.
Here the excel file has 21 columns. I have to copy and replace cell data to slide shape in slide #8. How to increment the cell value horizontally? Like a1 to b1 till 21 cells and repeat the same from beginning
here the code
Sub xltoppt()
Dim xlApp As Object
Dim xlWorkBook As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkBook = xlApp.Workbooks.Open("C:\Users\\Desktop\test.xls", True, False)
Set xlApp = Nothing
Set xlWorkBook = Nothing
Dim SheetName As String
Dim TestRange As Range
Dim TestSheet As Worksheet
Dim PasteRange As Boolean
Dim RangePasteType As String
Dim RangeName As String
Dim AddSlidesToEnd As Boolean
Dim shts As Worksheet
Dim sld As Slide
Dim grpItem As Shape
Dim shp As Shape
Dim i As Long
Dim j As Long
SheetName = ActiveSheet.Name
'Setting PasteRange to True means that Chart Option will not be used
PasteRange = True
RangeName = ("B1:B1") '"MyRange"
RangePasteType = "HTML"
RangeLink = True
PasteChart = False
PasteChartLink = True
ChartNumber = 1
AddSlidesToEnd = True
'Error testing
On Error Resume Next
Set TestSheet = Sheets(SheetName)
Set TestRange = Sheets(SheetName).Range(RangeName)
Set TestChart = Sheets(SheetName).ChartObjects(ChartNumber)
On Error GoTo 0
'If TestSheet Is Nothing Then
'MsgBox "Sheet " & SheetName & " does not exist. Macro will exit", vbCritical
Exit Sub
'End If
'If PasteRange And TestRange Is Nothing Then
MsgBox "Range " & RangeName & " does not exist. Macro will exit", vbCritical
Exit Sub
'End If
'Look for existing instance
'On Error Resume Next
'Set ppApp = GetObject(, "PowerPoint.Application")
'On Error GoTo 0
'Create new instance if no instance exists
''If ppApp Is Nothing Then Set ppApp = New PowerPoint.Application
'Add a presentation if none exists
'If ppApp.Presentations.Count = 0 Then ppApp.Presentations.Add
'Make the instance visible
ppApp.Visible = True
'Check that a slide exits, if it doesn't add 1 slide. Else use the last slide for the paste operation
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = replace(shp.TextFrame.TextRange.Text, "happy", Worksheets(SheetName).Range(RangeName))
End If
End If
Next shp
Next
End Sub```
I have specific columns' names in Excel that I want to copy and paste into PowerPoint but I can't run the code because I get "Run Error 424." I have tried using ("B3:Q3") for the columns and that works. However, I don't want all those columns, I only want the columns that are listed below ("b3,f3,l3,n3,p3,q3").
Can anyone assist? Thank you so much!
Sub ExcelRangeToPowerPoint()
Dim rng As Range
Dim rng1 As Range
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim myShape As Object
'Copy Range from Excel
Set rng = ThisWorkbook.ActiveSheet.Range("b3,f3,l3,n3,p3,q3").Select 'THIS IS THE ERROR
Set rng1 = ThisWorkbook.ActiveSheet.Range("G4:I4")
'Create an Instance of PowerPoint
On Error Resume Next
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")
'Clear the error between errors
Err.Clear
'If PowerPoint is not already open then open PowerPoint
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
'Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If
On Error GoTo 0
'Optimize Code
Application.ScreenUpdating = False
'Create a New Presentation
Set myPresentation = PowerPointApp.Presentations.Add
'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly
'Copy Excel Range
rng.Copy
'Paste to PowerPoint and position
mySlide.Shapes.PasteSpecial DataType:=7 '7 = ppPasteText
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
'Set position:rng
myShape.Left = 70
myShape.Top = 150
myShape.Width = 800
myShape.Height = 100
'Copy Excel Range
rng1.Copy
'Paste to PowerPoint and position
mySlide.Shapes.PasteSpecial DataType:=7 '7 = ppPasteText
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
'Set position:rng
myShape.Left = 70
myShape.Top = 200
myShape.Width = 800
myShape.Height = 300
'Insert the tile on the ppt
mySlide.Shapes.Title.TextFrame.TextRange.Text = "Insert Title Here"
'Make PowerPoint Visible and Active
PowerPointApp.Visible = True
PowerPointApp.Activate
'Clear The Clipboard
Application.CutCopyMode = False
End Sub
Take off the .Select.
1) You can't Set Rng = [whatever].Select. You want to do Set Rng = [whatever] then Rng.Select on a new line, but more importantly,
2) It's best to Avoid using .Select/.Activate. Although you don't seem to use it elsewhere (good!), so I bet this is just a "typo".
Also, if you want the Columns then you would do:
Set rng = ThisWorkbook.ActiveSheet.Range("b3,f3,l3,n3,p3,q3").EntireColumn
Edit: This won't solve the issue of it pasting the in-between columns, but this (admittedly a little klunky) code will select just the data used (including headers), instead of the entire columns:
'Copy Range from Excel
Dim lastRow As Long
With ThisWorkbook.ActiveSheet
lastRow = .Cells(Rows.Count, 2).End(xlUp).Row
' I assume your headers actually are in row 3, and the data is in row 4 on ward:
Set rng = ThisWorkbook.ActiveSheet.Range("b3:B" & lastRow & ",f3:F" & lastRow & ",l3:l" & lastRow & ",n3:N" & lastRow & ",p3:P" & lastRow & ",q3:Q" & lastRow)
Set rng1 = ThisWorkbook.ActiveSheet.Range("G4:I4")
End With
'Create an Instance of PowerPoint
On Error Resume Next
' Etc. etc.
I've been wrestling with using Excel to create PowerPoint slide using a .potx file as the powerpoint template.
The problem I have is that I am not able to figure out how to duplicate the slidemaster so I can use custom layouts.
I want a new presentation created that uses the layouts defined in the .potx file?
I'm brand new to VBA so my code is a little rough on the edges.
Sub ExcelRangeToPowerPoint()
'PURPOSE: Copy/Paste An Excel Range Into a New PowerPoint Presentation
'SOURCE: www.TheSpreadsheetGuru.com
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim myShape As Object
Dim mytextbox As Object
Dim Ws As Worksheet
Dim trueranges As New Collection 'Store the ranges to be used in master excel file
Dim start_counting_from_this_row_number As Integer 'starting value of rows to search for TRUE/FALSE
Dim worksheetnames As New Collection 'collect all worksheet names if TRUE
Dim rg As Range
Const PXLtoINCH As Single = 72# 'PP uses pixels not inches, this is the conversion factor
Dim SQPOSITION As Double
Dim SQHeight As Double
Dim range_shape As New WSOrgDisplayAttributes
Dim all_data As New Collection
'*******************************************************************************************************************
'Check to see if Master Data Sheet Spreadsheet is in same directory and if so, open it.
Dim FilePath As String
Dim FileNameOnly As String
FileNameOnly = "WS Asset Availability Master Data Spreadsheet.xlsx"
FilePath = ActiveWorkbook.Path & "\" & FileNameOnly
If IsFile(FilePath) = True Then 'ENDIF is near the end of the SUB
If CheckFileIsOpen(FileNameOnly) = False Then
Workbooks.Open (FileName)
MsgBox ("A small time Delay...(This ensures file is open and ready for use")
Application.Wait (Now + TimeValue("00:00:10")) 'this allows time to open before other parts of macro run
End If
'*******************************************************************************************************************
'*******************************************************************************************************************
'Create an Instance of PowerPoint
On Error Resume Next
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(Class:="PowerPoint.Application")
'Clear the error between errors
Err.Clear
'If PowerPoint is not already open then open PowerPoint
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(Class:="PowerPoint.Application")
'Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If
On Error GoTo 0
'Optimize Code
Application.ScreenUpdating = False
'Create a New Presentation
Set myPresentation = PowerPointApp.Presentations.Add
myPresentation.ApplyTemplate (ThisWorkbook.Path & "\" & "SRR Template.potx")
'myPresentation.ApplyTemplate (FilePath & "\" & "SRR Template.potx")
'*******************************************************************************************************************
'*******************************************************************************************************************
'Initialize variables
start_counting_from_this_row_number = 3 'Find row where first TRUE/FALSE is under column "D"
Set rg = ThisWorkbook.Sheets("SRR Helper").Range("D1").CurrentRegion 'count the max rows
SQPOSITION = 6 'inches
SQHeight = 0.18 'inches
'*******************************************************************************************************************
'*******************************************************************************************************************
'Push all TRUE's to collections
'ADD HEADER INFO LATER
For x = start_counting_from_this_row_number To rg.Rows.Count
If ThisWorkbook.Sheets("SRR Helper").Range("D" & x).Value = True Then
Set range_shape = Nothing
range_shape.let_range_check = True
range_shape.let_shape_range = ThisWorkbook.Sheets("SRR Helper").Range("C" & x).Value
range_shape.let_sheet_name = ThisWorkbook.Sheets("SRR Helper").Range("E" & x).Value
all_data.Add range_shape
End If
Next x
'*******************************************************************************************************************
'*******************************************************************************************************************
'Iterate through collections to push Master File to PP presenation
Dim iterator As New WSOrgDisplayAttributes
Dim iterator2 As New WSOrgDisplayAttributes
Set mySlide = myPresentation.Slides.Add(1, 1) 'Always create at least one slide myPresentation.Designs(1).SlideMaster.CustomLayouts (GetLayoutIndexFromName("SRRLayout", myPresentation.Designs(1)))
myPresentation.PageSetup.SlideSize = ppSlideSizeOnScreen 'Set slide orientation and size
Dim sheet_counter As Integer
sheet_counter = 1
Dim updateslide As Boolean
Dim temp As Double
temp = (SQPOSITION) * PXLtoINCH
For i = 1 To all_data.Count
'Set Worksheet
Set iterator = all_data(i)
Set iterator2 = Nothing
If all_data.Count = 1 Then
updateslide = False 'only one sheet so no need for new slide, they are equal
Else
If i = all_data.Count Then ' last element can't be compared with the next, but can be compared to previous
Set iterator2 = all_data(i - 1)
If iterator2.get_sheet_name = iterator.get_sheet_name Then
updateslide = False
Else
updateslide = True
sheet_counter = sheet_counter + 1
End If
Else
Set iterator2 = all_data(i + 1)
If iterator2.get_sheet_name = iterator.get_sheet_name Then
updateslide = False
Else
updateslide = True
sheet_counter = sheet_counter + 1
End If
End If
End If
Set Ws = Workbooks("WS Asset Availability Master Data Spreadsheet.xlsx").Sheets(iterator.get_sheet_name)
'Copy Range from Excel
Set rg = Ws.Range(iterator.get_shape_range)
'Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
Application.Wait (Now + TimeValue("00:00:1"))
'Copy Excel Range
rg.Copy
'Paste to PowerPoint and position
mySlide.Shapes.PasteSpecial DataType:=2 '2 = ppPasteEnhancedMetafile
Set myShape = mySlide.Shapes(mySlide.Shapes.Count) 'Control the latest shape to be pasted
'Set position:
myShape.LockAspectRatio = msoTrue
myShape.Height = 0.62 * PXLtoINCH
myShape.Width = 9.74 * PXLtoINCH
myShape.Left = 0.14 * PXLtoINCH
myShape.Top = temp
temp = myShape.Top + myShape.Height
If updateslide = True Then
temp = (SQPOSITION) * PXLtoINCH ' reset temp back to starting position.
End If
'Add a slide to the Presentation - only if new sheetname
If updateslide = True Then
Set mySlide = myPresentation.Slides.Add(sheet_counter, 2) '11 = ppLayoutTitleOnly
updateslide = False
temp = (SQPOSITION) * PXLtoINCH
End If
Next i
'*******************************************************************************************************************
'*******************************************************************************************************************
'Make PowerPoint Visible and Active
PowerPointApp.Visible = True
PowerPointApp.Activate
'Clear The Clipboard
Application.CutCopyMode = False
'*******************************************************************************************************************
'*******************************************************************************************************************
Else
MsgBox ("File Does not Exist in local directory - WS Asset Availability Master Data Spreadsheet.xlsx")
End If
End Sub
Function IsFile(ByVal fName As String) As Boolean
'Returns TRUE if the provided name points to an existing file.
'Returns FALSE if not existing, or if it's a folder
On Error Resume Next
IsFile = ((GetAttr(fName) And vbDirectory) <> vbDirectory)
End Function
Function CheckFileIsOpen(chkSumfile As String) As Boolean
On Error Resume Next
CheckFileIsOpen = (Workbooks(chkSumfile).Name = chkSumfile)
On Error GoTo 0
End Function
Function GetLayoutIndexFromName(sLayoutName As String, oDes As Design) As Long
Dim x As Long
For x = 1 To oDes.SlideMaster.CustomLayouts.Count
If oDes.SlideMaster.CustomLayouts(x).Name = sLayoutName Then
GetLayoutIndexFromName = x
Exit Function
End If
Next
End Function
Hello I am try to copy an image from excel into powerpoint. My code already copy and pastes into excel but I am having an issue with the code that would automate the resizing. With this current code I get object required Runtime error 424. Any help would be appreciated. MY abbreviated code is below.
Sub CopyDataToPPT()
'Const ppLayoutBlank = 12
Dim objWorkSheet As Worksheet
Dim objRange As Range
Dim objPPT As PowerPoint.Application
Dim objPresentation As Presentation
Dim shapePPTOne As Object
Dim intLocation As Integer
Dim intHeight As Integer
Dim inLayout As Integer
Dim strRange As String
Dim boolOK As Boolean
Set objPPT = CreateObject("PowerPoint.Application")
Set objPresentation = objPPT.Presentations.Add
'First 1 Xor 2 charts
If Sheets("Summary Table").Cells(15, 4) <> "Not Found" Then
strRange = "B4:N24"
intHeight = 380
Else
strRange = "B4:N13"
intHeight = 190
End If
Set objslide = objPresentation.Slides.Add(1, inLayout)
objPresentation.Slides(1).Layout = ppLayoutTitleOnly
objPresentation.Slides(1).Shapes.Title.TextFrame.TextRange.Text = Sheets("Summary Table").Cells(2, 5) & " - " & Sheets("Summary Table").Cells(4, 2)
Set objRange = Sheets("Summary Table").Range(strRange)
objRange.Copy
DoEvents
Set shapePPTOne = objslide.Shapes.PasteSpecial(DataType:=ppPasteEnhancedMetafile, Link:=msoFalse)
shapePPTOne.Height = intHeight
shapePPTOne.Left = 50
shapePPTOne.Top = 100
Application.CutCopyMode = False
Next intLocation
This (a simplified version of your code) works fine for me:
Sub CopyDataToPPT()
Dim objslide
Dim objRange As Range
Dim objPPT As PowerPoint.Application
Dim objPresentation As Presentation
Dim shapePPTOne As Object
Set objPPT = CreateObject("PowerPoint.Application")
Set objPresentation = objPPT.Presentations.Add
Set objslide = objPresentation.Slides.Add(1, ppLayoutTitleOnly) 'you had inLayout???
objslide.Shapes.Title.TextFrame.TextRange.Text = "blah blah"
Sheets("Sheet1").Range("C6:G22").Copy
DoEvents
Set shapePPTOne = objslide.Shapes.PasteSpecial( _
DataType:=ppPasteEnhancedMetafile, Link:=msoFalse)
With shapePPTOne
.Height = 200
.Left = 50
.Top = 100
End With
Application.CutCopyMode = False
End Sub