VBA中的Powerpoint幻灯片计数变量 [英] Powerpoint Slide Count Variable in VBA

查看:125
本文介绍了VBA中的Powerpoint幻灯片计数变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在vba中创建一个Powerpoint.我的计划是设置代码,以便每个子例程创建一定的幻灯片.但是,我需要将幻灯片编号传递给每个子例程,以使其在正确的位置创建正确的幻灯片.我无法定义excel vba中的.Slides.Count.从技术上讲,我知道这是一个Long,但是我能够以某种方式将它作为Integer传递给另一个不再起作用的代码补丁.

I am creating a Powerpoint in vba. My plan is to set up the code such that each subroutine creates a certain slides. However I need to pass through the slide number to each subroutine in order for it to create the proper slide in the right position. I am having trouble defining what the .Slides.Count is in excel vba. I understand it is technically a Long, but somehow I was able to pass it through as an Integer in another patch of code that is no longer working.

我的问题是:

  1. .Slides.Count函数.从技术上讲是Long还是Integer.如果是Long,为什么要这样定义?是因为整数有上限,而多头没有上限?

  1. The .Slides.Count function. Is that technically a Long or an Integer. If it is a Long, why is it defined that way? Is it because integers have a cap and longs do not?

如何将.Slides.Count变量传递到创建新幻灯片的子例程中?作为整数还是Long?

How should I pass the .Slides.Count variable through into my subroutine that creates a new slide? As an Integer or Long?

我有一些示例代码:

Sub CreatePres()

Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide
Dim ppTextbox As PowerPoint.Shape

Set ppApp = New PowerPoint.Application
ppApp.Visible = True
ppApp.Activate

Set ppPres = ppApp.Presentations.Add
slidesCount = ppPres.Slides.Count
Set ppSlide = ppPres.Slides.Add(slidesCount + 1, ppLayoutTitle)
ppSlide.Shapes(1).TextFrame.TextRange.Text = "Hello world"
ppSlide.Shapes(2).TextFrame.TextRange.Text = Date
slidesCount = slidesCount + 1

Call slide2(slidesCount)

End Sub
Sub slide2(i As Integer)
Set ppSlide = ppPres.Slides.Add(i + 1, ppLayoutTitle)
ppSlide.Select
ppSlide.Shapes(1).TextFrame.TextRange.Text = "Hello world"
ppSlide.Shapes(2).TextFrame.TextRange.Text = Date

End Sub

推荐答案

设置当前幻灯片变量的方法是
foo = ActiveWindow.Selection.SlideRange.SlideIndex

The way to set a variable of the current slide is
foo = ActiveWindow.Selection.SlideRange.SlideIndex

因此,请使用Call slide2(slidesCount)

尝试以下

Sub CreatePres()
    Dim ppApp As PowerPoint.Application
    Dim ppPres As PowerPoint.Presentation
    Dim ppSlide As PowerPoint.Slide
    Dim ppTextbox As PowerPoint.Shape

    Set ppApp = New PowerPoint.Application
    ppApp.Visible = True
    ppApp.Activate

    Set ppPres = ppApp.Presentations.Add
    slidesCount = ppPres.Slides.Count
    Set ppSlide = ppPres.Slides.Add(slidesCount + 1, ppLayoutTitle)
    ppSlide.Shapes(1).TextFrame.TextRange.Text = "Hello world"
    ppSlide.Shapes(2).TextFrame.TextRange.Text = Date
    slidesCount = ActiveWindow.Selection.SlideRange.SlideIndex
    Call slide2(slidesCount)
End Sub

Sub slide2(i As Integer)
    Set ppSlide = ppPres.Slides.Add(i + 1, ppLayoutTitle)
    ppSlide.Select
    ppSlide.Shapes(1).TextFrame.TextRange.Text = "Hello world"
    ppSlide.Shapes(2).TextFrame.TextRange.Text = Date
End Sub

这篇关于VBA中的Powerpoint幻灯片计数变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆