L
Laphan
Hi All
Wondered if you could help.
A few months ago my friend wanted me to look at how I could cut down on the
amount of copying and pasting he has to do in a Word doc.
Basically he's a football scout for a amateur/semi-pro football team and he
creates a really long report per match on how the set plays go. Now the way
he's got it laid out is great, but he had to copy and paste the players'
names and numbers about 50 or so times into each set play.
What I did was make him enter the player names and numbers once at the top
of the Word doc using form fields (is that right - I mean the grey boxes :0)
and then I created reference/field tags in all of the other places so that
when he typed the name for player 1 then it would auto-type this name in all
of the other references. This worked great until I found that textboxes
don't update automatically so you have to either click into each textbox and
press F9 to update them or do I select all (still flaky and prone to foul
ups!) and press F9.
My solution to this was to use the following Macro code and tag it to a
button, which resides just under the grey boxes form:
Dim oField As Field, oStory As Range
ActiveDocument.Unprotect
For Each oStory In ActiveDocument.StoryRanges
Do
For Each oField In oStory.Fields
If oField.Type = wdFieldRef Then
oField.Update
End If
Next oField
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next oStory
MsgBox "Report populated"
This routine simply unlocked the form and then 'touched' each appropriate
textbox/field to cause the update. The final bit just brought up a message
box so that the user would know that all is done.
I saved the Word Doc as a template file and then let him use it. It saved
him ages and proved so successful that his mate started to use it as well.
Then after a few months something went wrong! It still works fine on his
WinXP SP2 laptop with Office 2003 SP2 and AVG 8 as his AV, but his mate's
laptop has stop updating. His mate has the exact same laptop as when it was
working, ie Vista Home with Office 2003, but I've noticed that he has
Virgin's PCGuard on it and his Office 2003 is now running as SP3.
The table type fields still populate OK on his laptop, but it's as if the
field update routine above isn't doing what it used to. I know the data is
there, because if I go into a field and press F9 it updates.
NOTE 1: both my friend and his mate both have Macro security set to Low as
this is the only Word doc they use on their computers. Sad I know but they
do have a combined age of 116!!
NOTE 2: I've tried running the Macro whilst it appears that Virgin's PC
guard is completely quit, but it still won't populate.
My questions are:
1) Is there a better way to get the textboxes to 'update' than the above
routine, as I'm more than willing to try something else as it does take a
good few mintues to complete even on a good spec dual-core machine?
2) Have you got any ideas why this doesn't work any more? Does it have
anything to do with SP3?
Thanks
Laphan
Wondered if you could help.
A few months ago my friend wanted me to look at how I could cut down on the
amount of copying and pasting he has to do in a Word doc.
Basically he's a football scout for a amateur/semi-pro football team and he
creates a really long report per match on how the set plays go. Now the way
he's got it laid out is great, but he had to copy and paste the players'
names and numbers about 50 or so times into each set play.
What I did was make him enter the player names and numbers once at the top
of the Word doc using form fields (is that right - I mean the grey boxes :0)
and then I created reference/field tags in all of the other places so that
when he typed the name for player 1 then it would auto-type this name in all
of the other references. This worked great until I found that textboxes
don't update automatically so you have to either click into each textbox and
press F9 to update them or do I select all (still flaky and prone to foul
ups!) and press F9.
My solution to this was to use the following Macro code and tag it to a
button, which resides just under the grey boxes form:
Dim oField As Field, oStory As Range
ActiveDocument.Unprotect
For Each oStory In ActiveDocument.StoryRanges
Do
For Each oField In oStory.Fields
If oField.Type = wdFieldRef Then
oField.Update
End If
Next oField
Set oStory = oStory.Next
Loop Until oStory Is Nothing
Next oStory
MsgBox "Report populated"
This routine simply unlocked the form and then 'touched' each appropriate
textbox/field to cause the update. The final bit just brought up a message
box so that the user would know that all is done.
I saved the Word Doc as a template file and then let him use it. It saved
him ages and proved so successful that his mate started to use it as well.
Then after a few months something went wrong! It still works fine on his
WinXP SP2 laptop with Office 2003 SP2 and AVG 8 as his AV, but his mate's
laptop has stop updating. His mate has the exact same laptop as when it was
working, ie Vista Home with Office 2003, but I've noticed that he has
Virgin's PCGuard on it and his Office 2003 is now running as SP3.
The table type fields still populate OK on his laptop, but it's as if the
field update routine above isn't doing what it used to. I know the data is
there, because if I go into a field and press F9 it updates.
NOTE 1: both my friend and his mate both have Macro security set to Low as
this is the only Word doc they use on their computers. Sad I know but they
do have a combined age of 116!!
NOTE 2: I've tried running the Macro whilst it appears that Virgin's PC
guard is completely quit, but it still won't populate.
My questions are:
1) Is there a better way to get the textboxes to 'update' than the above
routine, as I'm more than willing to try something else as it does take a
good few mintues to complete even on a good spec dual-core machine?
2) Have you got any ideas why this doesn't work any more? Does it have
anything to do with SP3?
Thanks
Laphan