如何确定文档是否为模板?

编程入门 行业动态 更新时间:2024-10-20 05:25:47
本文介绍了如何确定文档是否为模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图确定文档是简单文档(.doc,.docx,.docm)还是模板(.dot,.dotx,.dotm).

I am trying to figure out if a document is a simple document (.doc, .docx, .docm) or a template (.dot, .dotx, .dotm).

我知道有几种方法可以解决这个问题(例如检查文件扩展名),但是我正在寻找最安全"的方法.

I know there are several ways to figure this out (like check file extension), but I am looking for the most "safe" one.

我目前的猜测是:

Private Function isTemplate(ByVal Doc As Document) As Boolean isTemplate = (Doc.FullName = Doc.AttachedTemplate.FullName) End Function

这可以按预期工作,但是我想知道是否有一种更时尚的方式来实现这一目标.也许缺少isTemplate属性?邓诺.

This works as expected, but I would like to know if there is a more fashioned way to achieve this goal. Maybe some missing isTemplate property? dunno.

为什么:我已经在模板上创建了一个代码,以防止用户在没有密码保护的情况下保存文件.该代码的工作原理很吸引人,但是当我在模板中编辑某些内容时却感到无聊,因为它没有密码.

Why: I've created a code on a template to don't allow a user to save a file if it is not password protected. The code works like a charm, but it bores me when I am editing something in the template because it doesn't have a password.

推荐答案

感谢kmote,我找到了解决方案.

Thanks to kmote, I found the solution.

只需签入 SaveFormat 属性,如果该文档是模板(这里是此属性的可能值列表.

Just check in the SaveFormat property if the document is a Template (here is the list of possible values for this property).

Private Function isTemplate(ByVal Doc As Document) As Boolean Select Case Doc.SaveFormat Case wdFormatTemplate, wdFormatDocument97, _ wdFormatXMLTemplate, wdFormatXMLTemplateMacroEnabled, _ wdFormatFlatXMLTemplate, wdFormatFlatXMLTemplateMacroEnabled isTemplate = True Case Else isTemplate = False End Select End Function

更多推荐

如何确定文档是否为模板?

本文发布于:2023-11-29 17:14:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647057.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   文档

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!