|
-
May 19th, 2010, 08:12 AM
#1
Thread Starter
Lively Member
[RESOLVED] Footer field update...
Hi, Yep it's me again... sorry
We've had a few issues with different docs that contain fields, and those fields becoming blank after our previous code updates, so we wrote a new code that omits some drops down and input fields, so it doesn't update all.
The only prob is, the below code now update the fields but not the one we originally set out to update, The footer field. I've been at it a few hours now and can't seem to get it to work without it updating all fields, which we don't want to do. any help would be greatly appreciated.
Code:
Sub UpdateDocFields()
Dim iCount As Integer
Dim aField As Field
Dim DocProtect As Boolean
' If protected; unprotect document
If ActiveDocument.ProtectionType <> wdNoProtection Then
DocProtect = True
ActiveDocument.Unprotect
End If
' Loop through all text form fields in the document.
For Each aField In ActiveDocument.Fields
'If the form field is a text form OR drop down field...
If aField.Type = wdFieldFormTextInput Or aField.Type = wdFieldFormDropDown Then
'do nothing with FormText field
'MsgBox "Field not updated!" 'TEST MESSAGE ONLY - REMOVE FROM LIVE
Else
aField.Update
ActiveDocument.StoryRanges(wdPrimaryFooterStory).Fields.Update
aField.Update
'MsgBox "Field updated!" 'TEST MESSAGE ONLY - REMOVE FROM LIVE
End If
' Increment icount
iCount = iCount + 1
Next aField
'if document was originally protected, then re-protect
If DocProtect = True Then
ActiveDocument.Protect Password:="", NoReset:=True, Type:=wdAllowOnlyFormFields
End If
End Sub
-
May 19th, 2010, 08:44 AM
#2
Re: Footer field update...
Shouldn't you be updating the footer field like this?
Code:
ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(1).Range.Fields.Update
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
May 19th, 2010, 08:54 AM
#3
Thread Starter
Lively Member
Re: Footer field update...
Hi Sid,
Tried that one, and still no joy. I thought it was a bugged field code, as I F8'ed it and it ran but just didnt update with the new file path. do you think it might be getting confused with afield.update and the activedoc...update?
-
May 19th, 2010, 08:57 AM
#4
Re: Footer field update...
Let me cook some sample code for you...
Edit:
Try this...
Code:
'~~> Updates only fields in footer and no other fileds
Sub UpdateDocumentFooter()
Dim DocProtect As Boolean
'~~> If protected, unprotect document
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
DocProtect = True
End If
'~~> Prevent Screen Flickering
Application.ScreenUpdating = False
ActiveDocument.Sections(ActiveDocument.Sections.Count) _
.Footers(1).Range.Fields.Update
Application.ScreenUpdating = True
'~~> If document was originally protected, then re-protect
If DocProtect = True Then
ActiveDocument.Protect Password:="", NoReset:=True, _
Type:=wdAllowOnlyFormFields
End If
End Sub
Last edited by Siddharth Rout; May 19th, 2010 at 09:01 AM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
May 19th, 2010, 09:33 AM
#5
Thread Starter
Lively Member
Re: Footer field update...
As always Sid your a Don, Thanks for helping
Although I've tested the above, but same result, no change to the footer. I remmed out the old code and just tried the above, but with no luck.
-
May 19th, 2010, 09:35 AM
#6
Re: Footer field update...
Try this...
Code:
'~~> In some versions of Word you might have to move the selection
'~~> to the section you're updating
'~~> Updates only fields in footer and no other fileds
Sub UpdateDocumentFooter()
Dim iCount As Integer, DocProtect As Boolean
'~~> If protected, unprotect document
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
DocProtect = True
End If
'~~> Prevent Screen Flickering
Application.ScreenUpdating = False
'~~> move selection to end of document
Selection.EndKey wdStory
ActiveDocument.Sections(ActiveDocument.Sections.Count) _
.Footers(1).Range.Fields.Update
Application.ScreenUpdating = True
'~~> If document was originally protected, then re-protect
If DocProtect = True Then
ActiveDocument.Protect Password:="", NoReset:=True, _
Type:=wdAllowOnlyFormFields
End If
End Sub
If it still doesn't work then upload your file. Lemme have a look at it...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
May 19th, 2010, 10:14 AM
#7
Thread Starter
Lively Member
Re: Footer field update...
Hi Sid, Sorry my mistake, I started a fresh Normal.dot and the first and second codes you submitted worked fine, the normal I'm updating has been through the wars, updated and built apone for more then 4 years now.. needs a good clean up!
Thanks again...
-
May 19th, 2010, 10:17 AM
#8
Re: [RESOLVED] Footer field update...
lolzzz
You are welcome...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|