format text fields in word forms when protection is on

C

Carmen Perez

I wouldl ike to allow users to format the text inserted in text fields in a word form, ie. change to italics,bold, bullets, etc, whithout having to unprotect the form.
How could I do it, if possible?
Many thanks
 
J

Jean-Guy Marcil

Hi Carmen,

Look at the following code. It shoulkd get you going.
Then, build a toolbar and assign button to each font attribute function, or
assign keyboard short cuts, as you prefer.

'_______________________________________
Public myRange As Range
'_______________________________________
Sub Sel_Bold()

Sel_Unprotect

myRange.Bold = wdToggle

Sel_Protect

End Sub
'_______________________________________

'_______________________________________
Sub Sel_Italic()

Sel_Unprotect

myRange.Italic = wdToggle

Sel_Protect

End Sub
'_______________________________________

'_______________________________________
Sub Sel_Underline()

Sel_Unprotect

If myRange.Underline = wdUnderlineNone Then
myRange.Underline = wdUnderlineSingle
Else
myRange.Underline = wdUnderlineNone
End If

Sel_Protect

End Sub
'_______________________________________

'_______________________________________
Sub Sel_Unprotect()

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If

Set myRange = Selection.Range

End Sub
'_______________________________________

'_______________________________________
Sub Sel_Protect()

If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, _
Password:=""
End If

myRange.Select

End Sub
'_______________________________________


--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org


Carmen Perez said:
I wouldl ike to allow users to format the text inserted in text fields in
a word form, ie. change to italics,bold, bullets, etc, whithout having to
unprotect the form.
 
C

Carmen Perez

Thanx very much Jean Guy,
That looks exactly what I want (I would also like the possibility of bullets). Now, next questions are "where do I put that code?" and "some hints as to how to create that tool bar?" (Ithink I saw a link to a good web page somewhere in MVP web site?)
Sorry for my ignorance, I am almost new in this area!!!
 
W

Word Heretic

G'day Carmen Perez <[email protected]>,

www.mvps.org/word/FAQs/index.htm is yer website.

Create a new template, stick yer code in there and save your toolbar
customizations there as well.

Steve Hudson
Word Heretic Sydney Australia
Tricky stuff with Word or words

Email: WordHeretic at tpg.com.au


Carmen Perez was spinning this yarn:
 
J

Jean-Guy Marcil

Hi Carmen,

Open your template;
From the main Word Window hit ALT-F11;
The Visual Basic Editor (VBE) window will open;
In the VBE window you should see a project pane on the left and a main code
window to the right,
Make sure your document is active in the project pane (The tree view under
Project(Your document name) should be displayed, if not, click on the little
"+" next to it);
Right click Project(Your document name) and select Insert > Module;
Module1 should be added to your project;
Paste the code I posted in the code window (make sure that Module1 is
selected in the project pane first by double clicking on it);
Close the VBE window;
Save your template;
From the menu Tools choose Customize...;
Select the Toolbar tab;
Click on New;
Give a name to your toolbar;
It will appear floating on the screen, empty;
Dock it under the other toolbars at the top of the screen (click and drag);
Select the Commands tab in the customization dialog;
In the Categories section, scroll down to Macros;
In the Commands section on the right, scroll down to find the macros you
have just pasted (Project.Module1.Sel_Bold, etc.)
Select the first one of those, click and hold on its name, drag it to the
new toolbar you have just created;
Right click on the button you just have created and change its name to
something you like in the Name area and hit Enter;
Repeat for the other 2 macros (Project.Module1.Sel_Underline,
Project.Module1.Sel_Italic);
You will end up with a toolbar with 3 buttons on it;
If you prefer, you could have a dropdown type of menu with the three buttons
under that one dropdown button, for that, instead of placing the buttons
next to each other, before placing the three macros on the toolbar, scroll
to the end of the Categories section, you will see New menu, select it, in
the command section there will be only one item, drag it to your toolbar,
right click it to change its name, add the three buttons under that.

Try all this, when you have it working to your satisfaction, write back and
we will see what we can do about the bullets! (For that, you have to be
familiar with Paragraph styles... are you?)

HTH

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org


Carmen Perez said:
Thanx very much Jean Guy,
That looks exactly what I want (I would also like the possibility of
bullets). Now, next questions are "where do I put that code?" and "some
hints as to how to create that tool bar?" (Ithink I saw a link to a good web
page somewhere in MVP web site?)
 
C

Carmen Perez

Beautiful!!! IT'S ALL WORKING!
I even got the bullets (I duplicated a piece of your code and added an example I found in the online help)
I am still interested though in those paragraph styles (?). It will be great to add more functionality to the form, for example to allow users to define their own fonts, size, etc.
I have a problem left: the selection of text is very inflexible, ie it goes from the cursor to the end of the field, but doesn't allow to stop selecting before the end. Can that be changed?
I'll appeciate more help, although I got my major problems solved, so BIG THANXS.
 
J

Jean-Guy Marcil

Hi Carmen,

Glad it all worked out.

Unfortunately, I do not think there is anything you can do about making
"selecting text" easier in the form field (I was wondering how long it would
take you to come back here with that issue! You ~are~ quick!). Selecting the
first or last word in a field with the mouse can be difficult. You cannot
usually double click on the first or last word without selecting the whole
field, click and drag can be complicated, depending on the Word version. It
is usually more reliable with the SHIFT, CTRL and arrow keys on the keyboard

You could not let users create their own styles and add them to the toolbar
on the fly with a protected form. What you can do however, is create a set
of basic styles in your template and add those to the toolbar.

If you are not familiar with styles, I cannot urge you strongly enough to
learn to work with them. They are essential if you hope to become a Word
whiz! (or at least gain some control over what is going on in your
documents!)

I would suggest that you go to:
http://word.mvps.org/FAQs/Customization/CreateATemplatePart2.htm
(make sure you use the full URL if it gets wrapped).
This is a very informative page, then at the bottom, there is a Table of
contents, see the "Styles" section.

HTH

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org


Carmen Perez said:
Beautiful!!! IT'S ALL WORKING!
I even got the bullets (I duplicated a piece of your code and added an
example I found in the online help)
I am still interested though in those paragraph styles (?). It will be
great to add more functionality to the form, for example to allow users to
define their own fonts, size, etc.
I have a problem left: the selection of text is very inflexible, ie it
goes from the cursor to the end of the field, but doesn't allow to stop
selecting before the end. Can that be changed?
I'll appeciate more help, although I got my major problems solved, so BIG
THANXS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top