I am trying to open a excel file, take the ranges as picture and create a ppt our of it. I am not sure what is going wrong in the code below. Can someone help please? The code works well for all other slides coming from other excel file. The moment I opena excel file and switch , it is throwing "subscript out of range error"
Sub GlobalBankPPT()
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide
Dim ppShape As PowerPoint.Shape
Dim ppPic As Variant
Dim j As Integer
Dim wkb As Workbook
Dim sh As Worksheet
Dim WS_Count As Integer, i As Integer
Dim mypp As New ExcelToPPt.cPPt
mypp.InitFromTemplate MyTemplateppt:=mytemp, MyOutputppt:=""
Set ppApp = GetObject(, "PowerPoint.Application")
ppApp.Visible = msoTrue
Set ppPres = ppApp.ActivePresentation
Set wkb = Workbooks.Open(Filename:=ThisWorkbook.Worksheets("Index").Range ("FilePath"))
wkb.Activate
WS_Count = wkb.Worksheets.Count
For i = 1 To WS_Count
If Worksheets(i).Name = "Industry" Then
wkb.Activate
Set sh = ActiveSheet
Exit For
End If
Next I
'--------------------------------------------------------------------Slide7
Range(Sheet15.Range("A150"), Sheet15.Range("Q191")).Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ppPres.Slides(7).Select
Set ppPic = ppPres.Slides(7).Shapes.Paste
ppPic.Select
ppPic.Top = 70.24
ppPic.Width = 10.5 * 100
ppPic.Height = ppPic.Width / 3.4
ppPic.Left = 50
end sub
Related
The below code extracts data from the active PowerPoint presentation.
Sub ExportMultiplePowerPointSlidesToExcel()
'Declare our Variables
Dim ppApp As PowerPoint.Application
Dim PPTPres As PowerPoint.Presentation
Dim PPTSlide As PowerPoint.Slide
Dim PPTShape As PowerPoint.Shape
Dim PPTTable As PowerPoint.Table
Dim PPTPlaceHolder As PowerPoint.PlaceholderFormat
'Declare Excel Variables.
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlWrkSheet As Excel.Worksheet
Dim xlRange As Excel.Range
'Grab the Currrent Presentation.
Set ppApp = GetObject(, "PowerPoint.Application")
Set PPTPres = ppApp.ActivePresentation
Set PPTSlide = PPTPres.Slides(1)
'Grab the Currrent Presentation.
'Keep going if there is an error
On Error Resume Next
'Get the Active instance of Outlook if there is one
Set xlApp = GetObject(, "Excel.Application")
'If Outlook isn't open then create a new instance of Outlook
If Err.Number = 429 Then
'Clear Error
Err.Clear
'Create a new Excel App.
Set xlApp = New Excel.Application
'Make sure it's visible.
xlApp.Visible = True
'Add a new workbook.
Set xlBook = xlApp.Workbooks.Add
'Add a new worksheet.
Set xlWrkSheet = xlBook.Worksheets.Add
End If
'Set the Workbook to the Active one, if Excel is already open. THIS ASSUMES WE HAVE A WORKBOOK IN THE EXCEL APP.
Set xlBook = Workbooks("Cycle 2 - FSO Dirs and EDs - CCG Talent Review template.xlsm")
'Set the Worksheet to the Active one, if Excel is already open. THIS ASSUMES WE HAVE A WORKSHEET IN THE WORKBOOK.
Set xlWrkSheet = xlBook.Worksheets("CCG list")
Range("B3").Value = PPTSlide.Shapes(4).TextFrame.TextRange
Range("E3").Value = PPTSlide.Shapes(7).TextFrame.TextRange
'Set the Worksheet Column Width.
xlWrkSheet.Columns.ColumnWidth = 20
'Set the Worksheet Row Height.
xlWrkSheet.Rows.RowHeight = 20
'Set the Horizontal Alignment so it's to the Left.
xlWrkSheet.Cells.HorizontalAlignment = xlLeft
'Turn off the Gridlines.
xlApp.ActiveWindow.DisplayGridlines = False
End Sub
How do I loop through the presentations in the current directory to perform the action?
I have attempted numerous methods but I can't seem to indicate each presentation. The name of the presentation should be irrelevant.
I am trying to open a powerpoint and then save it ( not save As) and close it. The problem looks like being htat the file isopened in REad-only Mode.
The code is this
Sub Macro()
Dim ObjPPT As PowerPoint.Application
Dim oPresentation As PowerPoint.Presentation
Dim oslide As PowerPoint.Slide
Dim oshape As PowerPoint.Shape
Dim i As Long
Dim opath As String
Set ObjPPT = New PowerPoint.Application
opath = "G:\Kommunikation_Meetings_Actions\Audits\Lean Audits\Lean Action Tracker & Production
Performance (VBA)\Daily KPI.pptx"
ObjPPT.Visible = msoCTrue
Set oPresentation = ObjPPT.Presentations.Open(opath, msoFalse)
'...........
oPresentation.Save
Application.Wait "00:00:05"
oPresentation.Close
End Sub
So when you right click a chart in Powerpoint and click Edit Data. A workbook will open up. I just want those data to be copied to my Excel file. Help me to extract every chart in each slide of powerpoint. Please help me Here's my code in PPT VBA so far:
Sub PowerpointToExcel()
Dim PPTPres As Presentation
Dim PPTSlide As Slide
Dim PPTShape As Shape
Dim PPTTable As Table
Dim PPTChart As Chart
Dim PPTPlaceHolder As PlaceholderFormat
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlRange As Excel.Range
Dim PPTChartData As MSForms.DataObject
Set PPTPres = Application.ActivePresentation
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
Set xlBook = xlApp.Workbooks("Book2.xlsx")
Set xlSheet = xlBook.Worksheets("Sheet2")
Set PPTChartData = New MSForms.DataObject
For Each PPTSlide In PPTPres.Slides
For Each PPTShape In PPTSlide.Shapes
If PPTShape.HasChart Then
Set PPTChart = PPTShape.Chart
Set xlRange = xlSheet.Range("A10000").End(xlUp)
If xlRange.Value <> "" Then
Set xlRange = xlRange.Offset(1, 0)
End If
With PPTPres.Slides(PPTSlide).Shapes(PPTShape).Chart.ChartData
.Activate
.Workbook.Sheets(1).Range("A2:E10").Copy
PPTChartData.GetFromClipboard
End With
SData = PPTChartData.GetText(1)
xlRange.Value = SData
xlRange.Offset(0, 1).Value = PPTSlide.Name
xlRange.Offset(0, 2).Value = PPTChart.ChartData
End If
Next
Next
End Sub
I'm trying to write a code to run from excel, and then open an existing excel and powerpoint file from the c drive, and use the data in the worksheet named "Oct18" to update the FIRST table in Slide 2 of the powerpoint.
The following is the code I wrote, but somehow it doesn't work.
May I know if anyone knows how to go about this please ?
Sub WriteText_toPPT_Table()
'Add a reference to Microsoft Powerpoint 12.0 object library
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppShp As PowerPoint.Shape
Dim ppSld As PowerPoint.slide
Dim xlworkbook As Workbook
Dim firstsheet As String
Dim fileDir As String
Dim excelFile As String
firstsheet = "Oct18"
'fileDir = "c:\masterpresentation.pptx"
'excelFile = "c:\masterexcel.pptx
'1) Open powerpoint application
Set ppApp = CreateObject("PowerPoint.Application")
ppApp.Visible = msoTrue
Set xlworkbook = Excel.Application.Workbooks.Open(Filename:=excelFile)
'2) opening an existing presentation
Set ppPres = ppApp.Presentations.Open(Filename:=fileDir)
Set exceldir = Excel.Application.Workbooks.Open(Filename:=excelFile)
ppPres.Slides(2).Shapes(1).Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = xlworkbook.Sheets(firstsheet).Cells(4, 12)
End Sub
Sub jede_Grafik_nach_PowerPoint()
'Extras - Verweise: Microsoft PowerPoint x.x Object Library
Dim Grafik As Shape
Dim PP As Object
Set PP = CreateObject("Powerpoint.Application")
Dim PP_Datei As PowerPoint.Presentation
Dim PP_Folie As PowerPoint.Slide
Dim ws As Worksheet
Dim wb As Workbook
Set wb = ThisWorkbook
Set PP_Datei = PP.Presentations.Open("C:\Users\akaygun\Desktop\test.pptm")
PP.Visible = msoTrue
'Set PP_Datei = PP.ActivePresentation wenn akt. Präsi sein soll
For Each ws In wb.Sheets
If Left(ws.Name, 3) = "MLK" Then
'neue Folie einfügen
PP_Datei.Slides(3).Copy
PP_Datei.Slides.Paste
Set PP_Folie = PP_Datei.Slides(PP_Datei.Slides.Count)
'copypaste
ws.Shapes("Stunden").Copy
PP_Folie.Shapes.Paste
PP_Folie.Shapes("Stunden").Top = 315.1991
PP_Folie.Shapes("Stunden").Left = 22.17449
ws.Shapes("Tage").Copy
PP_Folie.Shapes.Paste
PP_Folie.Shapes("Tage").Top = 10.16945
PP_Folie.Shapes("Tage").Left = -2.806772
End If
Next ws
End Sub
Dear Community,
I am trying to paste diagramms from excel to Powerpoint via VBA automatically.
When running this Sub it always says : "Remote server Computer doesnt exist"
'462'
I already tried to set a New Presentation instead of an Object but it did not help.