从 PowerPoint 操作按钮打开时,Word 宏无法正确运行

发布于 2024-09-30 19:04:06 字数 1209 浏览 0 评论 0原文

我有一个Word模板(来自建议),其中包括一个自动新建宏,用于在书签处插入参考编号,以及一个操作按钮(提交),该按钮将参考编号作为文件名的一部分保存结果文档并关闭Word。通过 Windows 资源管理器打开模板时,此功能非常有效。

我们还有一个 PowerPoint 演示,其中包含指向各种文档的超链接的操作设置。该链接将打开上述模板,但不会插入参考号。此外,当点击“提交”按钮时,文件将另存为另一个包含参考号的模板。

我不确定问题是与 Word 还是 PowerPoint 相关。 Word 模板的代码是

Sub AutoNew()

REF = System.PrivateProfileString("L:\Local\Lab\Section - Support Services\Health and Safety\H&S Suggestions\Settings.Txt", _
        "MacroSettings", "REF")

If REF = "" Then
    REF = 1
Else
    REF = REF + 1
End If

System.PrivateProfileString("L:\Local\Lab\Section - Support Services\Health and Safety\H&S Suggestions\Settings.Txt", "MacroSettings", _
        "REF") = REF

ActiveDocument.Bookmarks("REF").Range.InsertBefore Format(REF, "000#")


End Sub


Private Sub CommandButton1_Click()

REF = System.PrivateProfileString("L:\Local\Lab\Section - Support Services\Health and Safety\H&S Suggestions\Settings.Txt", _
        "MacroSettings", "REF")

ActiveDocument.SaveAs FileName:="L:\Local\Lab\Section - Support Services\Health and Safety\H&S Suggestions\Suggestion " & Format(REF, "000#.doc")
Application.Quit

End Sub

任何帮助或指针将不胜感激,就好像它有效一样我想将其用于各种其他模板。

I have a Word template (suggestion from) which includes an autonew macro to insert a reference number at a book mark and an action button (Submit)which saves the resulting document with the reference number as part of the file name and closes Word. This works perfectly well when opening the template via Windows Explorer.

We also have a PowerPoint show with action settings hyperlinking to various documents. The link will open the above template OK but does not insert the reference number. Also when the 'submit' button is hit, the file saves as another template with the reference number included.

I am not sure if the issue is Word or PowerPoint-related. The code for the Word template is

Sub AutoNew()

REF = System.PrivateProfileString("L:\Local\Lab\Section - Support Services\Health and Safety\H&S Suggestions\Settings.Txt", _
        "MacroSettings", "REF")

If REF = "" Then
    REF = 1
Else
    REF = REF + 1
End If

System.PrivateProfileString("L:\Local\Lab\Section - Support Services\Health and Safety\H&S Suggestions\Settings.Txt", "MacroSettings", _
        "REF") = REF

ActiveDocument.Bookmarks("REF").Range.InsertBefore Format(REF, "000#")


End Sub


Private Sub CommandButton1_Click()

REF = System.PrivateProfileString("L:\Local\Lab\Section - Support Services\Health and Safety\H&S Suggestions\Settings.Txt", _
        "MacroSettings", "REF")

ActiveDocument.SaveAs FileName:="L:\Local\Lab\Section - Support Services\Health and Safety\H&S Suggestions\Suggestion " & Format(REF, "000#.doc")
Application.Quit

End Sub

Any help or pointers would be appreciated as if it works I'd like to use for various other templates.

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

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

发布评论

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

评论(1

旧时光的容颜 2024-10-07 19:04:06

从描述中,很难准确地了解正在发生的情况,但听起来 AUTONEW 可能无法在该特定组合中运行。

您可以通过使用一些日志记录或 MSGBOX 调用来验证这一点,以准确查看正在运行的宏以及何时运行。

在此处查看有关 Autonew 的文档

http://support.microsoft.com/kb/211659

听起来像如果宏以“正常”保存,它将不会运行,这听起来不像这里的情况,但值得注意。

您还可以考虑使用 AutoOpen 宏并检查其他元素,以确保这是一个全新的文档,而不是已保存的文档(例如检查 Document.Fullname 属性的内容)。

From the description, it's kind of hard to get an accurate idea of what's happening, but it SOUNDS like the the AUTONEW just might not get run in that particular combination.

You could verify this by using some logging or MSGBOX calls to see exactly what macros are being run, when.

Check the docs on Autonew here

http://support.microsoft.com/kb/211659

Sounds like it won't run if the macro is saved in Normal, which doesn't sound like the case here but it's worth noting.

You might also consider using the AutoOpen macro and checking other elements to make sure this is a brand new doc instead of one that's already been saved (like checking the content of the Document.Fullname property).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文