Group:  Microsoft Word ยป microsoft.public.word.vba.customization
Thread: Word 2003 - one too many field updates

Geek News

Word 2003 - one too many field updates
"Nick Fluck" <nick[ at ]fluck.org> 6/16/2007 9:59:57 PM
I am a novice (eejit..) macro / VBA user.

I have a template document in which I use fillin fields to prompt for
references, name and address lines and header lines.

I want to use a simple (taken me about four hours cutting and pasting and
testing and restarting so far!!) VBA routine to prompt for and set custom
document properties. (Code to date set out below) and I also want to be
able to check an existing document when I reopen it to see if I want to
update the custom document properties.

This creates a problem though as the updating of document properties when
either the original or the update code causes the fillin fields to run,
twice, once before the prompt for the custom doc properties and once after
them (and again at print time!)

Is there a way to force the custom document properties to update BEFORE and
without affecting fillin fields?

There is one more silly quirk with what I have done to date and this is
that, as the docproperty fields in my template don't get updated until after
the initial display of an "Error doc property doesn't exist"
in BOLD the docproperty items end up bold when they are entered as they
pick up the formatting of the displayed field error.

See I told you I was an eejit!

Code:

Sub AutoNew()

Dim ClientRef As String
Dim FeeRef As String
Dim SecRef As String
Dim oStory As Range

ClientRef = InputBox("Enter Client reference (Letter and 6 numbers)",
"ClientRef", "")
FeeRef = InputBox("Enter Fee-Earner initials", "FeeRef", "")
SecRef = InputBox("Enter Secretary's initials", "SecRef", "")
'ActiveDocument.Variables("ClientName").Value = ClientName
ActiveDocument.CustomDocumentProperties.Add Name:="ClientRef",
LinkToContent:=False, Value:=ClientRef, Type:=msoPropertyTypeString
ActiveDocument.CustomDocumentProperties.Add Name:="FeeRef",
LinkToContent:=False, Value:=FeeRef, Type:=msoPropertyTypeString
ActiveDocument.CustomDocumentProperties.Add Name:="SecRef",
LinkToContent:=False, Value:=SecRef, Type:=msoPropertyTypeString
'ActiveDocument.BuiltInDocumentProperties("Author").Value = Author
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType < wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
End Sub

Sub AutoOpen()

Dim ClientRef As String
Dim FeeRef As String
Dim SecRef As String
Dim oStory As Range

On Error GoTo ExitSub
Update = MsgBox("Update Document Information? NB has no effect unless custom
document properties have already been set", vbYesNo)
If Update = vbYes Then
ClientRef = InputBox("Enter Client reference(Letter and 6 numbers)",
"ClientRef", "")
FeeRef = InputBox("Enter Fee-Earner initials", "FeeRef", "")
SecRef = InputBox("Enter Secretary's initials", "SecRef", "")
ActiveDocument.CustomDocumentProperties("ClientRef").Value = ClientRef
ActiveDocument.CustomDocumentProperties("FeeRef").Value = FeeRef
ActiveDocument.CustomDocumentProperties("SecRef").Value = SecRef

'ActiveDocument.Variables("PolicyNum").Value = PolicyNum
'ActiveDocument.BuiltInDocumentProperties("Author").Value = Author

For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType < wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
End If
ExitSub:
End Sub


Any help would be much appreciated and I will not be in the least offended
if everyone wants to tell me how stupidly I have set about this project!

thanks

Nick Fluck


Re: Word 2003 - one too many field updates
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 6/16/2007 10:24:02 PM
I would suggest that instead of your InputBoxes and Fillin fields, you use a
userform.

See the article "How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Nick Fluck" <nick[ at ]fluck.org> wrote in message
news:%23LhKnGGsHHA.3484[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
>I am a novice (eejit..) macro / VBA user.
>
> I have a template document in which I use fillin fields to prompt for
> references, name and address lines and header lines.
>
> I want to use a simple (taken me about four hours cutting and pasting and
> testing and restarting so far!!) VBA routine to prompt for and set custom
> document properties. (Code to date set out below) and I also want to be
> able to check an existing document when I reopen it to see if I want to
> update the custom document properties.
>
> This creates a problem though as the updating of document properties when
> either the original or the update code causes the fillin fields to run,
> twice, once before the prompt for the custom doc properties and once after
> them (and again at print time!)
>
> Is there a way to force the custom document properties to update BEFORE
> and without affecting fillin fields?
>
> There is one more silly quirk with what I have done to date and this is
> that, as the docproperty fields in my template don't get updated until
> after the initial display of an "Error doc property doesn't exist"
> in BOLD the docproperty items end up bold when they are entered as they
> pick up the formatting of the displayed field error.
>
> See I told you I was an eejit!
>
> Code:
>
> Sub AutoNew()
>
> Dim ClientRef As String
> Dim FeeRef As String
> Dim SecRef As String
> Dim oStory As Range
>
> ClientRef = InputBox("Enter Client reference (Letter and 6 numbers)",
> "ClientRef", "")
> FeeRef = InputBox("Enter Fee-Earner initials", "FeeRef", "")
> SecRef = InputBox("Enter Secretary's initials", "SecRef", "")
> 'ActiveDocument.Variables("ClientName").Value = ClientName
> ActiveDocument.CustomDocumentProperties.Add Name:="ClientRef",
> LinkToContent:=False, Value:=ClientRef, Type:=msoPropertyTypeString
> ActiveDocument.CustomDocumentProperties.Add Name:="FeeRef",
> LinkToContent:=False, Value:=FeeRef, Type:=msoPropertyTypeString
> ActiveDocument.CustomDocumentProperties.Add Name:="SecRef",
> LinkToContent:=False, Value:=SecRef, Type:=msoPropertyTypeString
> 'ActiveDocument.BuiltInDocumentProperties("Author").Value = Author
> For Each oStory In ActiveDocument.StoryRanges
> oStory.Fields.Update
> If oStory.StoryType < wdMainTextStory Then
> While Not (oStory.NextStoryRange Is Nothing)
> Set oStory = oStory.NextStoryRange
> oStory.Fields.Update
> Wend
> End If
> Next oStory
> Set oStory = Nothing
> End Sub
>
> Sub AutoOpen()
>
> Dim ClientRef As String
> Dim FeeRef As String
> Dim SecRef As String
> Dim oStory As Range
>
> On Error GoTo ExitSub
> Update = MsgBox("Update Document Information? NB has no effect unless
> custom document properties have already been set", vbYesNo)
> If Update = vbYes Then
> ClientRef = InputBox("Enter Client reference(Letter and 6 numbers)",
> "ClientRef", "")
> FeeRef = InputBox("Enter Fee-Earner initials", "FeeRef", "")
> SecRef = InputBox("Enter Secretary's initials", "SecRef", "")
> ActiveDocument.CustomDocumentProperties("ClientRef").Value = ClientRef
> ActiveDocument.CustomDocumentProperties("FeeRef").Value = FeeRef
> ActiveDocument.CustomDocumentProperties("SecRef").Value = SecRef
>
> 'ActiveDocument.Variables("PolicyNum").Value = PolicyNum
> 'ActiveDocument.BuiltInDocumentProperties("Author").Value = Author
>
> For Each oStory In ActiveDocument.StoryRanges
> oStory.Fields.Update
> If oStory.StoryType < wdMainTextStory Then
> While Not (oStory.NextStoryRange Is Nothing)
> Set oStory = oStory.NextStoryRange
> oStory.Fields.Update
> Wend
> End If
> Next oStory
> Set oStory = Nothing
> End If
> ExitSub:
> End Sub
>
>
> Any help would be much appreciated and I will not be in the least offended
> if everyone wants to tell me how stupidly I have set about this project!
>
> thanks
>
> Nick Fluck
>


Re: Word 2003 - one too many field updates
"Nick Fluck" <nick[ at ]fluck.org> 6/17/2007 11:34:33 AM
Thanks for this, Doug.

I have had a play with a simple userform (thank you for this - I can see a
whole new sea of finger problems opening before me now!) but this reveals
another lack of knowledge which may be crucial!

I wanted to have a single text box for "address" details but although I can
make this multiline it doesn't seem to be possible to start a new line using
only the CR key but only by holding shift and CR. This would cause my users
endless grief so I swapped the address lines for individual one-line text
boxes and this in turn means I now need to know how to get rid of unused
bookmarks and closing up the used ones to be on sequential lines

Thus

addr1
addr2
addr4
addr5

even though addr3 is blank.

Any thoughts - and thanks very much once again for your blindingly swift
earlier response.

regards

Nick Fluck
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> wrote in message
news:%23pyYUUGsHHA.1864[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
>I would suggest that instead of your InputBoxes and Fillin fields, you use
>a userform.
>
> See the article "How to create a Userform" at:
>
> http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Nick Fluck" <nick[ at ]fluck.org> wrote in message
> news:%23LhKnGGsHHA.3484[ at ]TK2MSFTNGP05.phx.gbl...
>>I am a novice (eejit..) macro / VBA user.
>>
>> I have a template document in which I use fillin fields to prompt for
>> references, name and address lines and header lines.
>>
>> I want to use a simple (taken me about four hours cutting and pasting and
>> testing and restarting so far!!) VBA routine to prompt for and set custom
>> document properties. (Code to date set out below) and I also want to be
>> able to check an existing document when I reopen it to see if I want to
>> update the custom document properties.
>>
>> This creates a problem though as the updating of document properties when
>> either the original or the update code causes the fillin fields to run,
>> twice, once before the prompt for the custom doc properties and once
>> after them (and again at print time!)
>>
>> Is there a way to force the custom document properties to update BEFORE
>> and without affecting fillin fields?
>>
>> There is one more silly quirk with what I have done to date and this is
>> that, as the docproperty fields in my template don't get updated until
>> after the initial display of an "Error doc property doesn't exist"
>> in BOLD the docproperty items end up bold when they are entered as they
>> pick up the formatting of the displayed field error.
>>
>> See I told you I was an eejit!
>>
>> Code:
>>
>> Sub AutoNew()
>>
>> Dim ClientRef As String
>> Dim FeeRef As String
>> Dim SecRef As String
>> Dim oStory As Range
>>
>> ClientRef = InputBox("Enter Client reference (Letter and 6 numbers)",
>> "ClientRef", "")
>> FeeRef = InputBox("Enter Fee-Earner initials", "FeeRef", "")
>> SecRef = InputBox("Enter Secretary's initials", "SecRef", "")
>> 'ActiveDocument.Variables("ClientName").Value = ClientName
>> ActiveDocument.CustomDocumentProperties.Add Name:="ClientRef",
>> LinkToContent:=False, Value:=ClientRef, Type:=msoPropertyTypeString
>> ActiveDocument.CustomDocumentProperties.Add Name:="FeeRef",
>> LinkToContent:=False, Value:=FeeRef, Type:=msoPropertyTypeString
>> ActiveDocument.CustomDocumentProperties.Add Name:="SecRef",
>> LinkToContent:=False, Value:=SecRef, Type:=msoPropertyTypeString
>> 'ActiveDocument.BuiltInDocumentProperties("Author").Value = Author
>> For Each oStory In ActiveDocument.StoryRanges
>> oStory.Fields.Update
>> If oStory.StoryType < wdMainTextStory Then
>> While Not (oStory.NextStoryRange Is Nothing)
>> Set oStory = oStory.NextStoryRange
>> oStory.Fields.Update
>> Wend
>> End If
>> Next oStory
>> Set oStory = Nothing
>> End Sub
>>
>> Sub AutoOpen()
>>
>> Dim ClientRef As String
>> Dim FeeRef As String
>> Dim SecRef As String
>> Dim oStory As Range
>>
>> On Error GoTo ExitSub
>> Update = MsgBox("Update Document Information? NB has no effect unless
>> custom document properties have already been set", vbYesNo)
>> If Update = vbYes Then
>> ClientRef = InputBox("Enter Client reference(Letter and 6 numbers)",
>> "ClientRef", "")
>> FeeRef = InputBox("Enter Fee-Earner initials", "FeeRef", "")
>> SecRef = InputBox("Enter Secretary's initials", "SecRef", "")
>> ActiveDocument.CustomDocumentProperties("ClientRef").Value = ClientRef
>> ActiveDocument.CustomDocumentProperties("FeeRef").Value = FeeRef
>> ActiveDocument.CustomDocumentProperties("SecRef").Value = SecRef
>>
>> 'ActiveDocument.Variables("PolicyNum").Value = PolicyNum
>> 'ActiveDocument.BuiltInDocumentProperties("Author").Value = Author
>>
>> For Each oStory In ActiveDocument.StoryRanges
>> oStory.Fields.Update
>> If oStory.StoryType < wdMainTextStory Then
>> While Not (oStory.NextStoryRange Is Nothing)
>> Set oStory = oStory.NextStoryRange
>> oStory.Fields.Update
>> Wend
>> End If
>> Next oStory
>> Set oStory = Nothing
>> End If
>> ExitSub:
>> End Sub
>>
>>
>> Any help would be much appreciated and I will not be in the least
>> offended if everyone wants to tell me how stupidly I have set about this
>> project!
>>
>> thanks
>>
>> Nick Fluck
>>
>
>


Re: Word 2003 - one too many field updates
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 6/17/2007 7:45:15 PM
Dim address as String
address = ""
If addr1 <> "" then
address = address & addr1.text
End if
If addr2 <> "" then
address = address & vbCr & addr2.text
End if
If addr3 <> "" then
address = address & vbCr & addr3.text
End if

etc

ActiveDocument.Bookmarks("Address").Range.InsertBefore address

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Nick Fluck" <nick[ at ]fluck.org> wrote in message
news:%23YqO0NNsHHA.4020[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
> Thanks for this, Doug.
>
> I have had a play with a simple userform (thank you for this - I can see a
> whole new sea of finger problems opening before me now!) but this reveals
> another lack of knowledge which may be crucial!
>
> I wanted to have a single text box for "address" details but although I
> can make this multiline it doesn't seem to be possible to start a new line
> using only the CR key but only by holding shift and CR. This would cause
> my users endless grief so I swapped the address lines for individual
> one-line text boxes and this in turn means I now need to know how to get
> rid of unused bookmarks and closing up the used ones to be on sequential
> lines
>
> Thus
>
> addr1
> addr2
> addr4
> addr5
>
> even though addr3 is blank.
>
> Any thoughts - and thanks very much once again for your blindingly swift
> earlier response.
>
> regards
>
> Nick Fluck
> "Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> wrote in message
> news:%23pyYUUGsHHA.1864[ at ]TK2MSFTNGP04.phx.gbl...
>>I would suggest that instead of your InputBoxes and Fillin fields, you use
>>a userform.
>>
>> See the article "How to create a Userform" at:
>>
>> http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm
>>
>>
>> --
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>>
>> "Nick Fluck" <nick[ at ]fluck.org> wrote in message
>> news:%23LhKnGGsHHA.3484[ at ]TK2MSFTNGP05.phx.gbl...
>>>I am a novice (eejit..) macro / VBA user.
>>>
>>> I have a template document in which I use fillin fields to prompt for
>>> references, name and address lines and header lines.
>>>
>>> I want to use a simple (taken me about four hours cutting and pasting
>>> and testing and restarting so far!!) VBA routine to prompt for and set
>>> custom document properties. (Code to date set out below) and I also
>>> want to be able to check an existing document when I reopen it to see if
>>> I want to update the custom document properties.
>>>
>>> This creates a problem though as the updating of document properties
>>> when either the original or the update code causes the fillin fields to
>>> run, twice, once before the prompt for the custom doc properties and
>>> once after them (and again at print time!)
>>>
>>> Is there a way to force the custom document properties to update BEFORE
>>> and without affecting fillin fields?
>>>
>>> There is one more silly quirk with what I have done to date and this is
>>> that, as the docproperty fields in my template don't get updated until
>>> after the initial display of an "Error doc property doesn't exist"
>>> in BOLD the docproperty items end up bold when they are entered as they
>>> pick up the formatting of the displayed field error.
>>>
>>> See I told you I was an eejit!
>>>
>>> Code:
>>>
>>> Sub AutoNew()
>>>
>>> Dim ClientRef As String
>>> Dim FeeRef As String
>>> Dim SecRef As String
>>> Dim oStory As Range
>>>
>>> ClientRef = InputBox("Enter Client reference (Letter and 6 numbers)",
>>> "ClientRef", "")
>>> FeeRef = InputBox("Enter Fee-Earner initials", "FeeRef", "")
>>> SecRef = InputBox("Enter Secretary's initials", "SecRef", "")
>>> 'ActiveDocument.Variables("ClientName").Value = ClientName
>>> ActiveDocument.CustomDocumentProperties.Add Name:="ClientRef",
>>> LinkToContent:=False, Value:=ClientRef, Type:=msoPropertyTypeString
>>> ActiveDocument.CustomDocumentProperties.Add Name:="FeeRef",
>>> LinkToContent:=False, Value:=FeeRef, Type:=msoPropertyTypeString
>>> ActiveDocument.CustomDocumentProperties.Add Name:="SecRef",
>>> LinkToContent:=False, Value:=SecRef, Type:=msoPropertyTypeString
>>> 'ActiveDocument.BuiltInDocumentProperties("Author").Value = Author
>>> For Each oStory In ActiveDocument.StoryRanges
>>> oStory.Fields.Update
>>> If oStory.StoryType < wdMainTextStory Then
>>> While Not (oStory.NextStoryRange Is Nothing)
>>> Set oStory = oStory.NextStoryRange
>>> oStory.Fields.Update
>>> Wend
>>> End If
>>> Next oStory
>>> Set oStory = Nothing
>>> End Sub
>>>
>>> Sub AutoOpen()
>>>
>>> Dim ClientRef As String
>>> Dim FeeRef As String
>>> Dim SecRef As String
>>> Dim oStory As Range
>>>
>>> On Error GoTo ExitSub
>>> Update = MsgBox("Update Document Information? NB has no effect unless
>>> custom document properties have already been set", vbYesNo)
>>> If Update = vbYes Then
>>> ClientRef = InputBox("Enter Client reference(Letter and 6 numbers)",
>>> "ClientRef", "")
>>> FeeRef = InputBox("Enter Fee-Earner initials", "FeeRef", "")
>>> SecRef = InputBox("Enter Secretary's initials", "SecRef", "")
>>> ActiveDocument.CustomDocumentProperties("ClientRef").Value =
>>> ClientRef
>>> ActiveDocument.CustomDocumentProperties("FeeRef").Value = FeeRef
>>> ActiveDocument.CustomDocumentProperties("SecRef").Value = SecRef
>>>
>>> 'ActiveDocument.Variables("PolicyNum").Value = PolicyNum
>>> 'ActiveDocument.BuiltInDocumentProperties("Author").Value = Author
>>>
>>> For Each oStory In ActiveDocument.StoryRanges
>>> oStory.Fields.Update
>>> If oStory.StoryType < wdMainTextStory Then
>>> While Not (oStory.NextStoryRange Is Nothing)
>>> Set oStory = oStory.NextStoryRange
>>> oStory.Fields.Update
>>> Wend
>>> End If
>>> Next oStory
>>> Set oStory = Nothing
>>> End If
>>> ExitSub:
>>> End Sub
>>>
>>>
>>> Any help would be much appreciated and I will not be in the least
>>> offended if everyone wants to tell me how stupidly I have set about this
>>> project!
>>>
>>> thanks
>>>
>>> Nick Fluck
>>>
>>
>>
>
>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net