[英]How do you create a new PowerPoint slide with text data from excel using VBA?
I've tried just modifying code from existing forums, but it's designed for an existing powerpoint and I want to create a new powerpoint with the info from excel already populated. 我尝试仅修改现有论坛中的代码,但它是为现有的PowerPoint设计的,我想使用已经填充的excel信息创建一个新的PowerPoint。 Can you tell me where I'm going wrong in my code? 您能告诉我代码中哪里出问题了吗?
Sub MarinePowerpoint()
Dim ws As Worksheet, wsB As Worksheet
Set ws = Worksheets("Overview")
Set wsB = Worksheets("Billing Rates")
Dim trueCount As Integer
Dim i As Integer
Dim Cst, Hrs
For i = 1 To 11
If ws.Range(Chr(65 + i) & "36").Value = "True" Then
trueCount = trueCount + 1
Cst = Cst + wsB.Range(Chr(66 + i) & "33").Value
Hrs = Hrs + wsB.Range(Chr(66 + i) & "25").Value
Scope = Scope + wsB.Range(Chr(66 + i) & "150").Value
End If
Next i
If trueCount > 0 Then
trueCount = trueCount + 1
Cst = Cst + wsB.Range(Chr(66 + i) & "33").Value
Hrs = Hrs + wsB.Range(Chr(66 + i) & "25").Value
Scope = Scope + wsB.Range(Chr(66 + i) & "150").Value
Data = "Cost: " & Cst _
& vbNewLine & "Hours: " & Hrs _
& vbNewLine & "Scope: " & Scope
'MsgBox Data
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slides
Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
Set PPPres = PPApp.Presentations.Add
PPPres.Range.Text = Data
End If
If trueCount = 0 Then
MsgBox "Please select engagement components."
End If
End Sub
Here's a bit of example code to add a shape with text: 这是一些添加文本形状的示例代码:
Sub Example()
Dim oSh As Shape
' On slide 1 of the currently active presentation:
With ActivePresentation.Slides(1)
' Add a rectangle at 100/100 left/top, 200/200 high and wide:
' Units are in points, 72 points = 1 inch
Set oSh = .Shapes.AddShape(msoShapeRectangle, 100, 100, 200, 200)
With oSh
' Ooo, let's make it bright red
.Fill.ForeColor.RGB = RGB(255, 0, 0)
' and some text:
With .TextFrame.TextRange
.Text = "Oooo, my face is red!"
' Format the text a bit:
With .Font
.Name = "Arial"
.Color.RGB = RGB(255, 255, 255)
.Size = 36 ' points
End With ' Font
End With ' Textrange
End With ' Shape
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.