LAM
07-31-2018, 06:05 AM
Hi Guys,
I have the problem that I always run into an error on the last row of the following code.
What I want to achieve is to left align the text in the textbox (per default it is centered).
Thanks for your help.
Best
Mathias
**************
Dim rng As Range
Dim rng2 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("F4:F4")
Set rng2 = ThisWorkbook.ActiveSheet.Range("E4:E4")
'Create an Instance of PowerPoint
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")
Set PowerPointApp = PowerPointApp.Presentations("Test.pptx")
PowerPointApp.Slides.Range(1).Select
'Add a slide to the Presentation
Set mySlide = PowerPointApp.Slides(1).Duplicate()(1)
'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, size and format:
myShape.Left = 26
myShape.Top = 104
myShape.Width = 312
myShape.Height = 40
myShape.Height = 40
myShape.TextFrame2.TextRange.Font.Size = 8
myShape.TextFrame2.TextRange.Font.Name = "Arial"
myShape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft
I have the problem that I always run into an error on the last row of the following code.
What I want to achieve is to left align the text in the textbox (per default it is centered).
Thanks for your help.
Best
Mathias
**************
Dim rng As Range
Dim rng2 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("F4:F4")
Set rng2 = ThisWorkbook.ActiveSheet.Range("E4:E4")
'Create an Instance of PowerPoint
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")
Set PowerPointApp = PowerPointApp.Presentations("Test.pptx")
PowerPointApp.Slides.Range(1).Select
'Add a slide to the Presentation
Set mySlide = PowerPointApp.Slides(1).Duplicate()(1)
'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, size and format:
myShape.Left = 26
myShape.Top = 104
myShape.Width = 312
myShape.Height = 40
myShape.Height = 40
myShape.TextFrame2.TextRange.Font.Size = 8
myShape.TextFrame2.TextRange.Font.Name = "Arial"
myShape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft