0
votes

I have used Custom Fields in my DOCX file and update them using OpenXML, but custom fields are not getting updated in document.

So I have write following macro to update field, it run well on my machine, Now i want to deploy it on each machine at client side, the machine count is 500 I can not go on each machine and paste macro code in each normal.dot file what is easy step to do it ? Or when I open word file, will application ask for installing macro ? like addin ?

Here is my macro

Private Sub Document_Open()
   Dim aStory As Range
   Dim aField As Field
   For Each aStory In ActiveDocument.StoryRanges
      For Each aField In aStory.Fields
         aField.Update
      Next aField
   Next aStory
End Sub
1
Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on Stack Overflow. See "Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?. BTW, it's "Thanks in advance", not "Thanks in advanced".John Saunders

1 Answers

0
votes

I don't know how to deploy your macro; however, in a comparable situation I sent users a template with the new macros and asked them to run it. The template would distribute the new macros. I ued the following code for that. Note that it only copies Macro Proejct Items (modules), not single macros:

Sub AutoNew()
    Deploy
End Sub
Sub AutoOpen()
    Deploy
End Sub

Sub Deploy()
Dim src, dst
    '
    If (MsgBox("This will deploy new macros to your Normal.dot. Continue?", vbYesNo, "Deploy new macros") _
        = vbNo) Then Exit Sub
On Error Resume Next
    src = ActiveDocument.AttachedTemplate.FullName
    dst = NormalTemplate.FullName
    '
    ' Copy a macro/module
    '
    Application.OrganizerCopy Source:=src, Destination:=dst, _
                Object:=wdOrganizerObjectProjectItems, Name:="Document_Open"
    '
    MsgBox "New macros have been copied to your Normal.dot. You can close this document now."
End Sub