我在powerpoint中有一个vba脚本,它是从第一张幻灯片上的按钮启动的,它将拍摄目录中的所有图像,并为每个图像创建一张幻灯片,并将所述图像导入到新创建的幻灯片中。 I&#34 ;.
有时,这些目录有几百到一千多个图像。我正在尝试更新标题幻灯片文本框以显示脚本在循环中的编号。但是,文本框实际更新的唯一时间是我在循环中使用断点,通常在行或行之后更新我的标题幻灯片文本框。我注意到如果我在文本框更新代码后添加了一个消息框,它也能正常工作。
我不明白发生了什么,或者为什么这不能做我想要/期望的事情。我期待第二个文本框改变它的内容,但是当它在循环中时,似乎vba跳过它。在循环完成之前,Debug.Print甚至不会执行(显示已注释,但我已将其取消注释)。
这是Slide1的代码的一部分,其中调用了导入函数。
If ButtonSelect = 1 Then //If user does not cancel the get directory popup
Call ImportPictures(dirPath, listFiles)
myTitleSlide.Shapes(2).TextFrame.TextRange.Text = "Images Imported"
myTitleSlide.Background.Fill.ForeColor.RGB = RGB(255, 255, 255)
Else
这是我在ImportPictures
中导入图片到幻灯片的循环我认识到这里有一些不好的编码实践,比如创建幻灯片对象而不是总是使用它,我可以稍后处理。
For i = 1 To UBound(listFiles, 1) + 1
importPath = directoryPath + listFiles(i - 1)
ActivePresentation.Slides(i + 1).Layout = ppLayoutBlank
ActivePresentation.SlideMaster.Background.Fill.ForeColor.RGB = RGB(0, 0, 0)
Set oSlide = ActivePresentation.Slides(i + 1)
oSlide.Shapes.AddTextbox(msoOrientationHorizontal, 5, 25, oPageWidth, 50).TextFrame.TextRange.Text = listFiles(i - 1)
oSlide.Shapes(1).TextFrame.TextRange.Font.Color.RGB = RGB(180, 180, 180)
oSlide.Shapes(1).TextFrame.TextRange.Font.Size = 13
' Set oPicture to the picture file on your computer. Set Link To
' File to false, Save With Document to true, and place it in the
' upper left-hand corner of the slide, sized to 1 by 1 points.
Set oPicture = oSlide.Shapes.AddPicture(importPath, _
msoFalse, msoTrue, 1, 1)
With oPicture
'set width to full slide with. Do not change height, to maintain original aspect ratio/format/don't stretch the image
.Width = ActivePresentation.PageSetup.SlideWidth
'set the top point so that the image is vertically centered
.Top = (ActivePresentation.PageSetup.SlideHeight - oPicture.Height) / 2
End With
'Show Current import number <- this doesn't work, and I don't know why
' ------THIS IS THE LINE IN QUESTION THAT ONLY WORKS WITH A BREAKPOINT-------------
ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange.Text = "Added" + CStr(i) + " of " + CStr(UBound(listFiles))
'Debug.Print "Added " + CStr(i) + " of " + CStr(UBound(listFiles))
Next i
感谢任何想法或帮助。
谢谢!