1

I am using the following VB Script in a Word 2010 Doc saved as a Microsoft Word Macro-Enabled Template that is protected for form fields:

Sub SaveWithBkMarkedText()
    'This code saves the Word file using the bookmark value for Maintenance Memo.
   'The file is also saved to a folder in KnowHow for files related to this template.
   Dim FileName As String
   FileName = ActiveDocument.Bookmarks("mmn").Range.Text
   'Use the C:\ code when saving the file locally
   ActiveDocument.SaveAs "C:\Download\TemplatesFolders\" & FileName & ".doc"
   MsgBox "Your Draft has been saved to KnowHow's Release Documentation site." & _
      &vbCrLf & "The file name uses the MM that you included earlier: " & FileName, _
       vbInformation + vbOKOnly, "Draft Saved to Minerva"
End Sub

The value entered into the Form Field for a FORMTEXT legacy-form object uses the Bookmark as the file name. Example, if the user enters 12345 as the value, the file is saved using this value as the filename: 12345.doc. This worked fine until a week ago when the filename is now being Prefixed with FORMTEXT 12345.doc. I have tried using this same VB script in older versions of Word on a different machine, and created from a NEW Template with the script added in from scratch, and the same issue is appearing on that machine as well. Prior to this, I was able to update my template with NO problem, but now I can't update this one FORMTEXT field without it affecting the whole file. I can update any other FORMTEXT in the template that does not use the Bookmark value as the file name, and it works. Also, I have tried changing the Bookmark Reference to another FORMTEXT object, as well as saving the file as a .DOCX and the same problem occurs regardless. What is causing the FORMTEXT to appear in the filename?

4

4 回答 4

0

您必须取消保护文档(模板),然后进行 VBA 编程。完成后,您可以再次保护它(用于填写表格),当您运行宏时,您将不会在文件名中看到“FORMTEXT”。希望能帮助到你。

于 2014-07-25T13:32:15.800 回答
0

对于OP,您解决了这个问题吗?我现在遇到了同样的问题,我正在使用带有书签的表单字段文本并使用 VB.net 来获取现在以 FORMTEXT 为前缀的bookmark.text,只使用它自己的书签并且它可以,没有前缀。我将尝试使用代码从结果中删除前 9 个字符,这是一种解决方法,是的,但它可能会起作用。

于 2015-04-29T07:01:47.657 回答
0

知道这是一个旧线程,但遇到了同样的问题。作为一种解决方法... 将 FORMTEXT 替换为 null ""。在OP情况下:

Dim FileName As String
   FileName = ActiveDocument.Bookmarks("mmn").Range.Text 
   FileName = Replace(FileName, "FORMTEXT ", "") 

不是问题的“修复”或优雅的,但它有效。

于 2015-05-14T05:58:36.500 回答
0

有同样的问题。只需删除当前书签并添加一个新书签。如果这不起作用,而不是使用以下内容:

FileName = ActiveDocument.Bookmarks("mmn").Range.Text

尝试使用:

Selection.GoTo What:=wdGoToBookmark, Name:="mmn"
Filename = Selection.Text
于 2018-09-14T07:30:40.397 回答