I have an excel document with rows of data in it. My goal is to be able to select a certain cell with text in it by marking it “Strength (#)” and then have that value paste into an already formatted powerpoint. There would be around 9 different markings I would have to paste, so my thought is do a for loop based on if the cell is marked. The code sets the variable and pastes the range, but it will not paste multiple items. It will keep pasting the cells on top of one another so the result is that my powerpoint will only contain what I have marked as “Strength 2”
[VBA]
Dim Strength1, Strength2 As Range
Dim mySlide, myShape, PowerPointApp, myPresentation As Object
Application.ScreenUpdating = False
Set PowerPointApp = GetObject(class:="Powerpoint.Application")
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="Powerpoint.Application")
Set myPresentation = PowerPointApp.Presentations.Open("C:/Desktop/test.pptx")
Set mySlide = myPresentation.Slides(1)
For b = 29 To 85
a = 50
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
myShape.Left = 25
myShape.Top = a
If ThisWorkbook.Worksheets("Comparisons").Cells(b, 8) = "Strength1" Then
Set Strength = ThisWorkbook.Worksheets("Comparisons").Cells(b, 2)
ElseIf ThisWorkbook.Worksheets("Comparisons").Cells(b, 8) = "Strength2" Then
Set Strength = ThisWorkbook.Worksheets("Comparisons").Cells(b, 2)
End If
With myShape
With .TextFrame
.TextRange.Text = Strength
.AutoSize = 1
With .TextRange.ParagraphFormat
.Alignment = ppAlignLeft
End With
With .TextRange.Font
.Size = 26
.Name = "Arial"
.Color.RGB = RGB(242, 105, 36)
End With
End With
End With
Set myShape = mySlide.Shapes(Count + 1)
a = a + 50
Next b
PowerPointApp.Visible = True
PowerPointApp.Activate
End Sub
[/VBA]
Bookmarks