bstephens
06-11-2011, 02:26 PM
I am looking to create a custom document property (the custom property called "DocID") on a save event, which then is updated in a { DOCPROPERTY "DocID" } field code in my footer as follows:
Suppose the user is working on a document called "X:\2011\70125.01\abc800.doc"
with the added complication, that sometimes users access the document through a search server and the document has a UNC name as "\\ro-server1\access\70125.01\abc800.doc"
Upon the user saving the document, the following complex string is written to a custom document property called "DocID"
2011\70125.01\abc800
Upon the save event, a field code which is already in the document called { DOCPROPERTY "DocID" } would automatically update and show the string "2011\70125.01\abc800"Where "2011\70125.01\abc800" is a string processed from ActiveDocument.FullName, and is processed the same regardless of whether the file has either a three letter extension (.doc) or a four letter extension (.docx), and regardless of whether the document is accessed from a mapped drive path or the UNC path (the UNC path is pretty static, so backing the string out, by counting from the fourth "\" symbol would probably be fine).
As far as updating the fields, I am already using the following repurposed save command from the ribbon to update fields, so I believe that part is handled, but I'm not clear how to write the custom document properties.
Anyone have ideas about writing the string to the custom document property upon save?
'Callback for FileSave onAction
Sub rxFileSave_repurpose(control As IRibbonControl, ByRef cancelDefault)
Call FileSave
Call UpdateFieldsALL
End Sub
'REPURPOSED SAVE COMMAND - Automatically updates the field upon a file SAVE event
Sub FileSave()
On Error Resume Next
ActiveDocument.Save
End Sub
Sub UpdateFieldsALL()
Dim sec As section
Application.ScreenUpdating = False
If Documents.Count = 0 Then Exit Sub
oldSaved = ActiveDocument.Saved
ActiveDocument.Fields.Update
For Each sec In ActiveDocument.Sections
sec.Headers(wdHeaderFooterPrimary).Range.Fields.Update
sec.Headers(wdHeaderFooterFirstPage).Range.Fields.Update
sec.Footers(wdHeaderFooterPrimary).Range.Fields.Update
sec.Footers(wdHeaderFooterFirstPage).Range.Fields.Update
Next
Application.ScreenUpdating = True
ActiveDocument.Saved = oldSaved
End Sub
Suppose the user is working on a document called "X:\2011\70125.01\abc800.doc"
with the added complication, that sometimes users access the document through a search server and the document has a UNC name as "\\ro-server1\access\70125.01\abc800.doc"
Upon the user saving the document, the following complex string is written to a custom document property called "DocID"
2011\70125.01\abc800
Upon the save event, a field code which is already in the document called { DOCPROPERTY "DocID" } would automatically update and show the string "2011\70125.01\abc800"Where "2011\70125.01\abc800" is a string processed from ActiveDocument.FullName, and is processed the same regardless of whether the file has either a three letter extension (.doc) or a four letter extension (.docx), and regardless of whether the document is accessed from a mapped drive path or the UNC path (the UNC path is pretty static, so backing the string out, by counting from the fourth "\" symbol would probably be fine).
As far as updating the fields, I am already using the following repurposed save command from the ribbon to update fields, so I believe that part is handled, but I'm not clear how to write the custom document properties.
Anyone have ideas about writing the string to the custom document property upon save?
'Callback for FileSave onAction
Sub rxFileSave_repurpose(control As IRibbonControl, ByRef cancelDefault)
Call FileSave
Call UpdateFieldsALL
End Sub
'REPURPOSED SAVE COMMAND - Automatically updates the field upon a file SAVE event
Sub FileSave()
On Error Resume Next
ActiveDocument.Save
End Sub
Sub UpdateFieldsALL()
Dim sec As section
Application.ScreenUpdating = False
If Documents.Count = 0 Then Exit Sub
oldSaved = ActiveDocument.Saved
ActiveDocument.Fields.Update
For Each sec In ActiveDocument.Sections
sec.Headers(wdHeaderFooterPrimary).Range.Fields.Update
sec.Headers(wdHeaderFooterFirstPage).Range.Fields.Update
sec.Footers(wdHeaderFooterPrimary).Range.Fields.Update
sec.Footers(wdHeaderFooterFirstPage).Range.Fields.Update
Next
Application.ScreenUpdating = True
ActiveDocument.Saved = oldSaved
End Sub