If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Updating docproperty value in multiple documents
Does anyone know if it is possible to automatically update
a docproperty value in multiple documents at once? I have a huge document I had to break into smaller docs but each doc needs to have the same version number. This is handled with a version number that is set in the Custom tab in the doc's Properties dialog box. |
#2
|
|||
|
|||
Updating docproperty value in multiple documents
Vicki,
This is rough and I hope one of the macor heavy hitters will come along and clean it up. I found a macro for doing batch find and replace in a directory. At first I thought I could just delete the find and replace bit and replace it with a command to set a docProperty. The problem I faced is that by simply setting a docProperty Word doesn't regonize the document has changed. I had to set a docProperty and then trick Word into thinking I made a recognized change (replaced all spaces with a space ;-) ). Here it is: Option Explicit Public Sub BatchReplaceDocProperties() Dim myFile As String Dim PathToUse As String Dim myDoc As Document Dim Expr1 As String On Error Resume Next 'Close all open documents before beginning Documents.Close SaveChanges:=wdPromptToSaveChanges 'Define Path (set to meet your needs) PathToUse = "D:\My Documents\Word Documents\Word Tips\Macros\" 'Solicit User Input (Set prompt and Title to meet your needs) Expr1 = InputBox("Enter the Document Subject:", "Subject") 'Set the directory and type of file to batch process myFile = Dir$(PathToUse & "*.doc") While myFile "" 'Open document Set myDoc = Documents.Open(PathToUse & myFile) 'Trick Word into thinking the document changed Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = " " .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue End With Selection.Find.Execute Replace:=wdReplaceAll 'Set DocProperty With myDoc 'This next line set the "Title" property to the value of Expr1 'Adapt to meet your needs .BuiltInDocumentProperties("Title").Value = Expr1 End With myDoc.Close SaveChanges:=wdSaveChanges 'Process next file in folder myFile = Dir$() Wend End Sub HTH If anyone can streamline this code or help me find a better way of saving the docProperty without having to use the find and replace bit please let me know. -- Greg Maxey A peer in "peer to peer" support Rockledge, FL To e-mail, edit out the "w...spam" in vicki wrote: Does anyone know if it is possible to automatically update a docproperty value in multiple documents at once? I have a huge document I had to break into smaller docs but each doc needs to have the same version number. This is handled with a version number that is set in the Custom tab in the doc's Properties dialog box. |
#3
|
|||
|
|||
Updating docproperty value in multiple documents
Hi Greg,
In place of 'Trick Word into thinking the document changed Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = " " .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue End With Selection.Find.Execute Replace:=wdReplaceAll Use myDoc.Saved = False -- Please post any further questions or followup to the newsgroups for the benefit of others who may be interested. Unsolicited questions forwarded directly to me will only be answered on a paid consulting basis. Hope this helps Doug Robbins - Word MVP "Greg Maxey" wrote in message om... Vicki, This is rough and I hope one of the macor heavy hitters will come along and clean it up. I found a macro for doing batch find and replace in a directory. At first I thought I could just delete the find and replace bit and replace it with a command to set a docProperty. The problem I faced is that by simply setting a docProperty Word doesn't regonize the document has changed. I had to set a docProperty and then trick Word into thinking I made a recognized change (replaced all spaces with a space ;-) ). Here it is: Option Explicit Public Sub BatchReplaceDocProperties() Dim myFile As String Dim PathToUse As String Dim myDoc As Document Dim Expr1 As String On Error Resume Next 'Close all open documents before beginning Documents.Close SaveChanges:=wdPromptToSaveChanges 'Define Path (set to meet your needs) PathToUse = "D:\My Documents\Word Documents\Word Tips\Macros\" 'Solicit User Input (Set prompt and Title to meet your needs) Expr1 = InputBox("Enter the Document Subject:", "Subject") 'Set the directory and type of file to batch process myFile = Dir$(PathToUse & "*.doc") While myFile "" 'Open document Set myDoc = Documents.Open(PathToUse & myFile) 'Trick Word into thinking the document changed Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = " " .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue End With Selection.Find.Execute Replace:=wdReplaceAll 'Set DocProperty With myDoc 'This next line set the "Title" property to the value of Expr1 'Adapt to meet your needs .BuiltInDocumentProperties("Title").Value = Expr1 End With myDoc.Close SaveChanges:=wdSaveChanges 'Process next file in folder myFile = Dir$() Wend End Sub HTH If anyone can streamline this code or help me find a better way of saving the docProperty without having to use the find and replace bit please let me know. -- Greg Maxey A peer in "peer to peer" support Rockledge, FL To e-mail, edit out the "w...spam" in vicki wrote: Does anyone know if it is possible to automatically update a docproperty value in multiple documents at once? I have a huge document I had to break into smaller docs but each doc needs to have the same version number. This is handled with a version number that is set in the Custom tab in the doc's Properties dialog box. |
Thread Tools | |
Display Modes | |
|
|