我正在用VBA创建Powerpoint幻灯片。我的计划是设置代码,使每个子程序都创建特定的幻灯片。但是,我需要将幻灯片编号传递给每个子程序,以便它可以在正确位置创建正确的幻灯片。我无法定义在Excel VBA中的 .Slides.Count。我知道它从技术上讲是Long,但是在另一个不再工作的代码片段中,我成功地将其传递为Integer。
我的问题如下:
- .Slides.Count函数。这从技术上讲是Long还是Integer?如果它是Long,为什么要这样定义呢?是因为整数有限制而长整型没有吗?
- 我该如何通过子程序将 .Slides.Count 变量传递到我的新幻灯片?作为Integer还是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