A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Word » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Updating docproperty value in multiple documents



 
 
Thread Tools Display Modes
  #1  
Old June 11th, 2004, 08:46 PM
vicki
external usenet poster
 
Posts: n/a
Default 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  
Old June 11th, 2004, 11:50 PM
Greg Maxey
external usenet poster
 
Posts: n/a
Default 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  
Old June 12th, 2004, 01:55 AM
Doug Robbins - Word MVP
external usenet poster
 
Posts: n/a
Default 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.




  #4  
Old June 12th, 2004, 04:12 AM
Greg Maxey
external usenet poster
 
Posts: n/a
Default Updating docproperty value in multiple documents

Thanks Doug.

--
Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
To e-mail, edit out the "w...spam" in

Doug Robbins - Word MVP wrote:
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


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:37 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.