Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-04-2015, 08:24 AM
vvcat vvcat is offline Can I modify header after form protection Windows 7 64bit Can I modify header after form protection Office 2007
Novice
Can I modify header after form protection
 
Join Date: Feb 2015
Location: HK
Posts: 14
vvcat is on a distinguished road
Default Can I modify header after form protection

Hi,



I know that if Word form is protected, the header/footer cannot be altered, is there any other ways to accomplish it or using VBA, etc. THanks
Reply With Quote
  #2  
Old 02-04-2015, 03:18 PM
macropod's Avatar
macropod macropod is offline Can I modify header after form protection Windows 7 64bit Can I modify header after form protection Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could do that with code like:
Code:
Sub ModifyHeader()
Application.ScreenUpdating = False
Dim Pwd As String, pState As Variant, Rng As Range, StrTxt As String
With ActiveDocument
  Set Rng = .Sections(1).Headers(wdHeaderFooterPrimary).Range
  Rng.End = Rng.End - 1
  StrTxt = InputBox("Please input the modified header text.", "Header Update", Rng.Text)
  If Trim(StrTxt) = "" Then Exit Sub
  pState = False
  If .ProtectionType <> wdNoProtection Then
    Pwd = InputBox("Please enter the Password", "Password")
    pState = .ProtectionType
    .Unprotect Pwd
  End If
  Rng.Text = StrTxt
  If pState <> wdNoProtection Then .Protect Type:=pState, NoReset:=True, Password:=Pwd
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-04-2015, 06:31 PM
vvcat vvcat is offline Can I modify header after form protection Windows 7 64bit Can I modify header after form protection Office 2007
Novice
Can I modify header after form protection
 
Join Date: Feb 2015
Location: HK
Posts: 14
vvcat is on a distinguished road
Default

Many thanks macropod,

I have added your script on VBA in Word file, pw is 123 for testing, but it seems missing something, after finishing the word file, how can I call the password field to unprotect the header, I uploaded the test file for reference.
Attached Files
File Type: docx test.docx (17.5 KB, 10 views)
Reply With Quote
  #4  
Old 02-04-2015, 06:44 PM
macropod's Avatar
macropod macropod is offline Can I modify header after form protection Windows 7 64bit Can I modify header after form protection Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

A couple of points:
1. Files in the docx format cannot contain macros, so there isn't one in your attachment.
2. Files using content controls don't need forms protection, so that's not necessary unless you have other reasons for using it.

As for the macro, you could run it via Alt-F11, or you could rename it to:
Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
insert as the first line:
If ContentControl.Title <> "MyTitle" Then Exit Sub
and place the code in your document's 'ThisDocument' code module. You would then apply the title 'MyTitle' to whatever content control you want to run the macro from. You can, of course, use something other than 'MyTitle' in both the code and the document.

If you don't want the password prompt, you could replace:
Pwd = InputBox("Please enter the Password", "Password")
with:
Pwd = "123"

That said, if all you want to achieve is having the content of one of your content controls replicated in the header, you don't need a macro. All you need do is apply a unique character Style to the content control, then use a STYLEREF field in the header to reference that Style.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 02-04-2015, 09:21 PM
vvcat vvcat is offline Can I modify header after form protection Windows 7 64bit Can I modify header after form protection Office 2007
Novice
Can I modify header after form protection
 
Join Date: Feb 2015
Location: HK
Posts: 14
vvcat is on a distinguished road
Default

Thanks Macropod,

Yes, docx cannot run macro..

Anyway, the original purpose is we want to set a form template and just let users to fill the Name, address, tel field only, we don't want users to modify the format in body.... and also, if we allow users to edit header under protection form condition, is your above VBA accomplish it. Many thanks.
Reply With Quote
  #6  
Old 02-04-2015, 11:25 PM
macropod's Avatar
macropod macropod is offline Can I modify header after form protection Windows 7 64bit Can I modify header after form protection Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by vvcat View Post
Yes, docx cannot run macro..
No, that is not what I said. A docx file can run any macro that is in its template.
Quote:
Anyway, the original purpose is we want to set a form template and just let users to fill the Name, address, tel field only, we don't want users to modify the format in body.... and also, if we allow users to edit header under protection form condition
In that case, add the macro to the template used to create these files. That way, you can still use the docx format.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I modify header after form protection One header without modify footers tanias Word 2 06-30-2014 11:55 AM
Can I modify header after form protection form field in header Snvlsfoal Word 1 07-12-2011 03:19 AM
How to remove this paragraph (line) form the header? Jamal NUMAN Word 1 04-14-2011 06:35 AM
Document protection Daved2424 Word 0 11-17-2010 01:22 AM
Form field to automatically be added to header? razberri Word VBA 3 02-22-2010 03:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:24 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft