Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Macro Help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Travis Montgomery - 04 Oct 2005 20:22 GMT
Hello all,

I'm trying to write a macro that will run upon exiting a dropdown box in
a protected word form.  What I'd like to do is, when a user chooses an
option in the dropdown box other than the fist choice, the text in the
box is changed to bold.  So far I have this code:

ActiveDocument.Unprotect
Selection.Font.Bold = True
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset

This gets me half way, if a user clicks on the box it changes to bold.
What I think I need now is an If then statement that checks the selected
text and if it does not equal "no change" (the default entry in the
dropdown) it bolds the text.

Can this be done, can anyone fill in the code that I need?

Thanks,

Travis
Signature

Travis Montgomery
Systems Analyst
IT - Systems and Procedures
E-Mail: tmontgomery_removethis@nccu.edu

Jay Freedman - 04 Oct 2005 20:59 GMT
Hi Travis,

Try this as the exit macro for the dropdown:

Sub ExitDD1()
  ActiveDocument.Unprotect
  If Selection.FormFields(1).DropDown.Value = 1 Then
     Selection.Font.Bold = False
  Else
     Selection.Font.Bold = True
  End If
  ActiveDocument.Protect wdAllowOnlyFormFields, True
End Sub

This code should be used *only* for a dropdown; running it on exit from any
other kind of form field will cause an error.

The .Value property is the number of the selected item in the dropdown list.
I used both the If and the Else so that if the user goes back and chooses
the first item again, the bolding is turned off.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Hello all,
>
[quoted text clipped - 17 lines]
>
> Travis
Travis Montgomery - 04 Oct 2005 21:13 GMT
Jay,

Thanks for the quick response.  This doesn't seem to work though I'm
guessing I missed a step as I I'm new at this.  Here's what I did.

1) Tools/macro/create/pasted the code you sent.
2) Double clicked on each drop down field and in the exit macro box
selected the macro
3) Saved the document/protected the document
4) Went to dropdown, selected 2nd option, left dropdown.

The text didn't change to bold.  Any more ideas?

Thanks,

Travis

> Hi Travis,
>
[quoted text clipped - 16 lines]
> I used both the If and the Else so that if the user goes back and chooses
> the first item again, the bolding is turned off.

Signature

Travis Montgomery
Systems Analyst
IT - Systems and Procedures
E-Mail: tmontgomery_removethis@nccu.edu

Jay Freedman - 05 Oct 2005 02:14 GMT
Travis,

It sounds like it should have worked, but there are always a few nasty
little details.

Open the macro editor (Alt+F11) and locate the macro. It should be in
a module named NewMacros in the Normal project (that's where the
Create button puts it by default).

Put the cursor on the Unprotect line and press F9 to insert a
breakpoint. Now go back to the document and tab out of the dropdown.
The macro editor should pop up with that line highlighted. Press F8
and watch the highlighting. Which lines does it go through?

For more information, right-click the word Value and select Add Watch,
and click OK in the watch dialog. As you step through the macro with
F8, what value shows in the watch window below?

Assuming the line with Bold = True executes, what shows in the field?

And yes, I did test the macro before I posted it, and it works as
advertised for me. :-)

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org

>Jay,
>
[quoted text clipped - 33 lines]
>> I used both the If and the Else so that if the user goes back and chooses
>> the first item again, the bolding is turned off.
Travis Montgomery - 05 Oct 2005 17:14 GMT
> And yes, I did test the macro before I posted it, and it works as
> advertised for me. :-)

Of this I had no doubt, this is why I was sure I was doing something
wrong.  I still don't know what it was but it seems to be working now.
I deleted the macro I had created.  Opened a fresh copy of the document,
tried again, seems to be working fine.

One more question:  Will the macro follow the document?

Thanks,

Travis

> Travis,
>
[quoted text clipped - 61 lines]
>>>I used both the If and the Else so that if the user goes back and chooses
>>>the first item again, the bolding is turned off.

Signature

Travis Montgomery
Systems Analyst
IT - Systems and Procedures
E-Mail: tmontgomery_removethis@nccu.edu

Jay Freedman - 05 Oct 2005 22:16 GMT
I'm glad it worked eventually!

>Will the macro follow the document?

Not if it's in your Normal.dot template (the Normal project as shown in the
macro editor).

You can select the project for the document and click Insert > Module. Then
cut the macro code from the Normal project and paste it into the new module,
and save the document. Then the macro will follow the document to another
PC. The downside of this is that if the other PC's macro security level (in
Tools > Macro > Security) is set to Medium, the user will get a warning
dialog every time they open the document, and have to click Enable to let
the macro work. If the level is set to High, there won't be any dialog and
the macro will be disabled -- it just won't execute at all. This means when
you send the form to people to fill out, you need to tell them to set the
level to Medium and click Enable.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

>> And yes, I did test the macro before I posted it, and it works as
>  > advertised for me. :-)
[quoted text clipped - 76 lines]
>>>> goes back and chooses the first item again, the bolding is turned
>>>> off.
Travis Montgomery - 06 Oct 2005 13:24 GMT
Yeah, I was afraid of that.

Thanks for all your help.

Travis

> I'm glad it worked eventually!
>
[quoted text clipped - 13 lines]
> you send the form to people to fill out, you need to tell them to set the
> level to Medium and click Enable.

Signature

Travis Montgomery
Systems Analyst
IT - Systems and Procedures
E-Mail: tmontgomery_removethis@nccu.edu

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.