Word,Ask-en REF velden,Sjabloon,VBA,macro [英] Word, Ask- en REF velden, Sjabloon, VBA, macro

查看:82
本文介绍了Word,Ask-en REF velden,Sjabloon,VBA,macro的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

L.S。,
$


我在Word文件中工作,其中包括Ask和Ref字段。通过询问有关此问题,我发现将文件另存为Word模板(.dotm)不是一个选项,因为打开模板后不包括Ask和Ref字段。
这是正确的吗?



但是,模板的操作是可取的。



我现在通过在文件中添加一个宏并将文件保存为带有启用宏(.docm)的Word来解决这个问题。



Sub AutoOpen()

'

AutoOpen Macro

'

'

    Selection.WholeStory

    Selection.Fields.Update

    ActiveDocument.Save



结束子

$
这样做的结果就是你得到了"另存为"仍然需要安排三件事的框架:



1.保存为Word文档(从.docm到.docx)

2一个新名称,例如:Doc(ument)1

   在此处添加:模板为文档的一个名称提供序列号。如果在VBA中可行,那就是     进一步改进。

3.路径可以与模板的位置相同为


保存为带有启用宏的Word模板(。 dotm)原来是无法解决的。然而,Ask和REF字段不包括在内。



有人可以帮我吗?
b
$
好​​奇关于反应。



Harry

L.S.,

I work within a Word file with, among other things, Ask and Ref fields. By asking questions about this, I found out that saving the file as a Word template (.dotm) is not an option because the Ask and Ref fields are not included after opening the template. Is this correct?

However, the operation of a template is desirable.

I have now solved this by adding a macro to the file and saving the file as Word with enabled macros (.docm).

Sub AutoOpen ()
'
AutoOpen Macro
'
'
    Selection.WholeStory
    Selection.Fields.Update
    ActiveDocument.Save

End Sub

The effect of this is that you get the 'Save as' framework in which three things still need to be arranged:

1. Save as Word document (from .docm to .docx)
2. A new name, for example: Doc(ument)1
    Added here: a template gives a sequential number for one name of a document. If that is possible within VBA, that would be      a further improvement.
3. The path can be the same as where the template is

Saving as Word Template with enabled macros (.dotm) turned out to be no solution. Yet the Ask and REF fields are not included.

Can someone help me with that?

Curious about a reaction.

Harry

推荐答案

ASK&模板中的REF字段会根据该模板复制到任何文档中。如果您创建一个名为" Counter"的数字
自定义文档属性。在你的模板中,y
你可以使用如下代码:

ASK & REF fields in a template do get replicated in any document based on that template. If you create a numeric Custom Document Property named "Counter" in your template, you could use code like:

Private Sub Document_New()

Dim strNm As String,i As Long

With ThisDocument

  strNm = Split(.FullName," .dot")(0)

  i = .CustomDocumentProperties(&"Counter")+ 1

  .CustomDocumentProperties("Counter")= i

  。保存¥b $ b结束时用
使用ActiveDocument

  .Fields.Update

  .SaveAs2 FileName:= strNm& " _" &安培;格式(i,"000")& " .docx",Fileformat:= wdFormatXMLDocument

结束与
结束子

Private Sub Document_New()
Dim strNm As String, i As Long
With ThisDocument
  strNm = Split(.FullName, ".dot")(0)
  i = .CustomDocumentProperties("Counter") + 1
  .CustomDocumentProperties("Counter") = i
  .Save
End With
With ActiveDocument
  .Fields.Update
  .SaveAs2 FileName:=strNm & "_" & Format(i,"000") & ".docx", Fileformat:=wdFormatXMLDocument
End With
End Sub

如果您要更新的字段在文档正文,将触发ASK字段并更新交叉引用。上面的代码也会将文档保存到与模板相同的文件夹中,并使用相同的名称和计数器
的值作为后缀。当然,您可以将其重新编码以保存到其他文件夹等。

Provided the fields you want to update are in the document body, the ASK field will be triggered and the cross-references updated. The above code will also save the document to the same folder as the template, with the same name and the value of the counter as a suffix. You could, of course, re-code it to save to a different folder, etc.


这篇关于Word,Ask-en REF velden,Sjabloon,VBA,macro的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆