自动为 ppt 文本框中的每个段落创建组合框

发布于 2024-11-27 12:25:10 字数 812 浏览 1 评论 0原文

我是 VBa 新手,最近遇到以下问题:我将数据(行)从 excel 工作表复制到 powerpoint 中,我想为我复制的每一行(因此对于 excel 中的每一行)创建一个组合框。我所能找到的只是如何通过 Powerpoint 中的菜单手动插入组合框,但我想避免手动添加这么多组合框。有没有办法通过 VBA 代码添加组合框?

Here is some of the code I use:

'Loop through each worksheet
 For Each objSheet In ActiveWorkbook.Worksheets

'Create new slide for the data
Set pptSld = pptPre.Slides.Add(Index:=pptPre.Slides.count + 1, Layout:=ppLayoutText)

'Paste the data to the text box of each slide
objSheet.UsedRange.Copy
pptSld.Shapes(2).TextFrame.TextRange.Paste

'Formatting the text box 2
pptSld.Shapes(2).TextFrame.TextRange.ParagraphFormat.Bullet = msoTrue
pptSld.Shapes(2).TextFrame.TextRange.ParagraphFormat.Bullet.RelativeSize = 1
pptSld.Shapes(2).TextFrame.TextRange.Font.Size = 16

    Next objSheet

如何继续?想要为每个工作表行定义一个组合框

i am new to VBa and recently encountered the following problem: I copy data (rows) from an excel sheet into powerpoint and I want to make a combobox for every line (so for every row in excel) that i copy. All I could find was how to manually insert comboboxes via the menu in Powerpoint but i want to avoid having to add so many manually. Is there a way to add the comboboxes via VBA code?

Here is some of the code I use:

'Loop through each worksheet
 For Each objSheet In ActiveWorkbook.Worksheets

'Create new slide for the data
Set pptSld = pptPre.Slides.Add(Index:=pptPre.Slides.count + 1, Layout:=ppLayoutText)

'Paste the data to the text box of each slide
objSheet.UsedRange.Copy
pptSld.Shapes(2).TextFrame.TextRange.Paste

'Formatting the text box 2
pptSld.Shapes(2).TextFrame.TextRange.ParagraphFormat.Bullet = msoTrue
pptSld.Shapes(2).TextFrame.TextRange.ParagraphFormat.Bullet.RelativeSize = 1
pptSld.Shapes(2).TextFrame.TextRange.Font.Size = 16

    Next objSheet

How to continue? Want to define a combo box for each sheet row

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落墨 2024-12-04 12:25:10

我不清楚您发布的代码与添加组合框有什么关系,但这里有一个如何添加组合框并向其中添加项目的示例:

Dim oSh As Shape
Dim oSl As Slide
Set oSl = ActivePresentation.Slides(1)

Set oSh = oSl.Shapes.AddOLEObject(Left:=168, Top:=24, Width:=192, Height:=24, ClassName:="Forms.ComboBox.1", Link:=msoFalse)
With oSh.OLEFormat.Object
    .AddItem ("This")
    .AddItem ("That")
    .AddItem ("The Other")
End With

I'm not clear on what the code you've posted has to do with adding combo boxes, but here's an example of how to add a combo box and add items to it:

Dim oSh As Shape
Dim oSl As Slide
Set oSl = ActivePresentation.Slides(1)

Set oSh = oSl.Shapes.AddOLEObject(Left:=168, Top:=24, Width:=192, Height:=24, ClassName:="Forms.ComboBox.1", Link:=msoFalse)
With oSh.OLEFormat.Object
    .AddItem ("This")
    .AddItem ("That")
    .AddItem ("The Other")
End With
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文