繁体   English   中英

将Excel文本周围的框添加到Powerpoint VBA

[英]Add box around text for Excel to Powerpoint VBA

我正在将数据从Excel导入到Powerpoint幻灯片中。 我如何能够在文本框周围添加框/轮廓? 还有什么方法可以添加不会移动的静态轮廓,即使我要导入的单元格中没有文本也是如此?

感谢您提供的所有帮助!

这是我的代码段:

Set ppSlide2 = ppPres.Slides.Add(i + 1, ppLayoutBlank).Shapes
Set HeaderPPT = ppSlide2.AddTextbox(msoTextOrientationHorizontal, 75, 150, 800, 700).TextFrame.TextRange
If Sheet1.Range("P" & RowExcel).Text = "Title" Then          
            With HeaderPPT
                .Text = vbNewLine & Cells(RowExcel, col + 9)
                .ParagraphFormat.Alignment = ppAlignCenter
                .Font.Bold = True
                .Font.Name = "Calibri Light"
                .Font.Size = 55
            End With
End If

TextFrame或TextRange没有border元素。 父级“形状”可以具有这样的边界。

Dim sld as Slide, shp as Shape
Set sld = Activepresentation.Slides(1)
Set shp = sld.Shapes.AddShapes(msoShapeRectangle, 100,100,100,100)
With shp
    .Line.Visible = True
    .Line.Weight = 2
    .Line.ForeColor.RGB = RGB(255,0,0)
End with

要放置静态边框,我认为您可以先添加一个矩形或TextBox。 然后再次添加带有Excel单元格内容的TextBox。 (但是,如果使用AddTextBox添加Textbox,则形状的边框默认情况下是静态的,即使其中没​​有文本也是如此。)

无论如何,我测试了以下代码:

Set ppSlide2 = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count, ppLayoutBlank).Shapes

'first, add a box(rectangle) or textbox so that the z-order can be lower than the next Textbox
Set HeaderBOX = ppSlide2.AddShape(msoShapeRectangle, 75, 150, 800, 700)
'or Set HeaderBOX = ppSlide2.AddTextbox(msoTextOrientationHorizontal, 75, 150, 800, 700)
With HeaderBOX
    .Name = "HeaderBOX"
    .Fill.Visible = False   'make it transparent
    .Line.Visible = True
    .Line.ForeColor.RGB = rgbBlack 'RGB(0,0,0)
    .Line.Weight = 2
End With

'then, add a textbox
Set HeaderPPT = ppSlide2.AddTextbox(msoTextOrientationHorizontal, 75, 150, 800, 700).TextFrame.TextRange
With HeaderPPT
    .Text = vbNewLine & "Excel Cell Text Here"
    .ParagraphFormat.Alignment = ppAlignCenter
    .Font.Bold = True
    .Font.Name = "Calibri Light"
    .Font.Size = 55
End With

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM