Group:  Microsoft Word » microsoft.public.word.docmanagement
Thread: Why_isn’t_this_macro_working?

Why_isn’t_this_macro_working?
blwrs 12/30/2008 11:52:01 PM
I recently inserted this macro in my word document (visual basic).

Sub OnExitDropDown1()
Dim oFFs As FormFields
Set oFFs = ActiveDocument.FormFields
Select Case oFFs("DropDown1").Result
Case "Person1"
oFFs("Text1").Result = "1376"
Case "Person2"
oFFs("Text1").Result = "4847"
Case "Person3"
oFFs("Text1").Result = "4805"
End Select
End Sub

Dropdown1 is my dropdown list of names and I would like their phone numbers
to automatically appear in a field “Text1”. I have the macro running on exit
of the dropdown menu. The problem I’m having is that the field “Text1” isn’t
automatically updating when I select the name in the dropdown menu. It will
work but I have to go to tools/macro and hit run every time I want it to
update.

Re: Why isn’t this macro working?
Jay Freedman <jay.freedman[ at ]verizon.net> 12/31/2008 12:19:59 AM
On Tue, 30 Dec 2008 15:52:01 -0800, blwrs <blwrs[ at ]discussions.microsoft.com>
wrote:

[Quoted Text]
>I recently inserted this macro in my word document (visual basic).
>
>Sub OnExitDropDown1()
>Dim oFFs As FormFields
>Set oFFs = ActiveDocument.FormFields
>Select Case oFFs("DropDown1").Result
> Case "Person1"
> oFFs("Text1").Result = "1376"
> Case "Person2"
> oFFs("Text1").Result = "4847"
> Case "Person3"
> oFFs("Text1").Result = "4805"
>End Select
>End Sub
>
>Dropdown1 is my dropdown list of names and I would like their phone numbers
>to automatically appear in a field “Text1”. I have the macro running on exit
>of the dropdown menu. The problem I’m having is that the field “Text1” isn’t
>automatically updating when I select the name in the dropdown menu. It will
>work but I have to go to tools/macro and hit run every time I want it to
>update.

It works perfectly well here. A couple of things to check:

- Did you protect the document for forms (click the lock icon on the forms
toolbar)?

- In the actual form, do the quoted names in the Case statements exactly match
the entries in the dropdown's properties, including cap/lower case and spaces?
(Probably they do, else running the macro from the dialog wouldn't work either.)

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
?
blwrs 12/31/2008 3:40:00 PM
Yes, I did protect the document and double checked the spelling etc.... still
no luck. I'm running 03, is that an issue?

"Jay Freedman" wrote:

[Quoted Text]
> On Tue, 30 Dec 2008 15:52:01 -0800, blwrs <blwrs[ at ]discussions.microsoft.com>
> wrote:
>
> >I recently inserted this macro in my word document (visual basic).
> >
> >Sub OnExitDropDown1()
> >Dim oFFs As FormFields
> >Set oFFs = ActiveDocument.FormFields
> >Select Case oFFs("DropDown1").Result
> > Case "Person1"
> > oFFs("Text1").Result = "1376"
> > Case "Person2"
> > oFFs("Text1").Result = "4847"
> > Case "Person3"
> > oFFs("Text1").Result = "4805"
> >End Select
> >End Sub
> >
> >Dropdown1 is my dropdown list of names and I would like their phone numbers
> >to automatically appear in a field “Text1”. I have the macro running on exit
> >of the dropdown menu. The problem I’m having is that the field “Text1” isn’t
> >automatically updating when I select the name in the dropdown menu. It will
> >work but I have to go to tools/macro and hit run every time I want it to
> >update.
>
> It works perfectly well here. A couple of things to check:
>
> - Did you protect the document for forms (click the lock icon on the forms
> toolbar)?
>
> - In the actual form, do the quoted names in the Case statements exactly match
> the entries in the dropdown's properties, including cap/lower case and spaces?
> (Probably they do, else running the macro from the dialog wouldn't work either.)
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
>
Re: Why isn’t this macro working?
Jay Freedman <jay.freedman[ at ]verizon.net> 12/31/2008 6:12:20 PM
No, running Word 2003 is not an issue. When I said "it works here", I had tried
it on Word 2003 and it works.

What is the setting in Tools > Macro > Security? If it's set to High, reset it
to Medium.

If that doesn't work, try making a different macro -- something simple, such as
just a MsgBox command to let you know when the macro runs -- and assign that as
the dropdown's exit macro. Does that work?

On Wed, 31 Dec 2008 07:40:00 -0800, blwrs <blwrs[ at ]discussions.microsoft.com>
wrote:

[Quoted Text]
>Yes, I did protect the document and double checked the spelling etc.... still
>no luck. I'm running 03, is that an issue?
>
>"Jay Freedman" wrote:
>
>> On Tue, 30 Dec 2008 15:52:01 -0800, blwrs <blwrs[ at ]discussions.microsoft.com>
>> wrote:
>>
>> >I recently inserted this macro in my word document (visual basic).
>> >
>> >Sub OnExitDropDown1()
>> >Dim oFFs As FormFields
>> >Set oFFs = ActiveDocument.FormFields
>> >Select Case oFFs("DropDown1").Result
>> > Case "Person1"
>> > oFFs("Text1").Result = "1376"
>> > Case "Person2"
>> > oFFs("Text1").Result = "4847"
>> > Case "Person3"
>> > oFFs("Text1").Result = "4805"
>> >End Select
>> >End Sub
>> >
>> >Dropdown1 is my dropdown list of names and I would like their phone numbers
>> >to automatically appear in a field “Text1”. I have the macro running on exit
>> >of the dropdown menu. The problem I’m having is that the field “Text1” isn’t
>> >automatically updating when I select the name in the dropdown menu. It will
>> >work but I have to go to tools/macro and hit run every time I want it to
>> >update.
>>
>> It works perfectly well here. A couple of things to check:
>>
>> - Did you protect the document for forms (click the lock icon on the forms
>> toolbar)?
>>
>> - In the actual form, do the quoted names in the Case statements exactly match
>> the entries in the dropdown's properties, including cap/lower case and spaces?
>> (Probably they do, else running the macro from the dialog wouldn't work either.)
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
>>

Home | Search | Terms | Imprint
Newsgroups Reader