如何更新 PowerPoint 幻灯片 (VBA) 中的所有日期/时间值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4080288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to update all date/time values in a PowerPoint slide (VBA)
提问by S'pht'Kr
I'm writing a PPT add-in that makes a PNG of a slide and uploads it somewhere. I want the slide creator to be able to add dates/times in text boxes (using Insert > Date & Time), and have those dates/times reflect the time the snapshot is taken.
我正在编写一个 PPT 插件,它可以制作幻灯片的 PNG 并将其上传到某个地方。我希望幻灯片创建者能够在文本框中添加日期/时间(使用插入 > 日期和时间),并使这些日期/时间反映拍摄快照的时间。
If one checks "Update Automatically" when adding them, the timestamps only update when the slide is opened. Is there a way to find all the date/time tags/fields in all shapes and force them to update immediately before I take the snapshot?
如果在添加时选中“自动更新”,则时间戳仅在幻灯片打开时更新。有没有办法找到所有形状的所有日期/时间标签/字段并强制它们在我拍摄快照之前立即更新?
The only other way I've found to possibly do what I want is to have "named" shapes on the slide that are empty and populate a date into them programmatically...but this introduces extra complexity for the person building the slide and is generally messier. But I'm open to other possibilities if any.
我发现可能做我想做的唯一另一种方法是在幻灯片上有“命名”形状,这些形状是空的,并以编程方式将日期填充到它们中……但这会给构建幻灯片的人带来额外的复杂性,并且是一般比较乱。但如果有的话,我对其他可能性持开放态度。
Thanks!
谢谢!
-EDIT-
-编辑-
Ok, I just realized that when I create the PNG with SaveGraphic the timestamps in the PNG are updated! So that probably is all I absolutelyneed. Interestingly though, the datestamps in what the user is looking at on-screen don't get updated, which is potentially confusing to the user. So the question still stands...seems like this should be doable.
好的,我刚刚意识到当我使用 SaveGraphic 创建 PNG 时,PNG 中的时间戳会更新!所以这可能就是我绝对需要的。但有趣的是,用户在屏幕上查看的日期戳不会更新,这可能会使用户感到困惑。所以问题仍然存在......似乎这应该是可行的。
采纳答案by Todd Main
Well, the bad news is you can't. The field (either as a Footer or input from e.g. TextRange.InsertAfter.InsertDateTime DateTimeFormat:=ppDateTimeMMddyyhmmAMPM, InsertAsField:=msoTrue
) works like this:
好吧,坏消息是你不能。该字段(作为页脚或来自 eg 的输入 TextRange.InsertAfter.InsertDateTime DateTimeFormat:=ppDateTimeMMddyyhmmAMPM, InsertAsField:=msoTrue
)的工作方式如下:
The DateTime will update when you run the slide deck only in the slide show window. When you exit that slide show window, you will see the earlier date/time of when the field was either inserted or or the presentation was opened. The field updates in the editing windows when the presentation is opened or inserted the first time.
当您仅在幻灯片放映窗口中运行幻灯片组时,DateTime 将更新。当您退出该幻灯片放映窗口时,您将看到插入字段或打开演示文稿的较早日期/时间。首次打开或插入演示文稿时,编辑窗口中的字段会更新。
There are only two ways to handle a situation like this:
处理这种情况只有两种方法:
- Force a close/reopen of your PowerPoint deck (which is an awful solution, but I had to mention it).
- Don't use the DateTime field the way
you have been. What I mean by this is
to control the date/time manually.
You can still use Insert Date/Time,
but manage the text boxes where it is
inserted so that you remove what is
in that text box and repopulate it
with a new
.InsertDateTime
each time you need it, such as before theSlide.Export
you are doing.
- 强制关闭/重新打开您的 PowerPoint 幻灯片(这是一个糟糕的解决方案,但我不得不提一下)。
- 不要像以前那样使用 DateTime 字段。我的意思是手动控制日期/时间。您仍然可以使用插入日期/时间,但管理插入它的文本框,以便您删除该文本框中的内容并在
.InsertDateTime
每次需要时重新填充它,例如在Slide.Export
您执行之前 。