Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-10-2014, 07:00 AM
supremegrandruler supremegrandruler is offline Macro not running on exiting legacy drop down menu. Windows 7 32bit Macro not running on exiting legacy drop down menu. Office 2007
Novice
Macro not running on exiting legacy drop down menu.
 
Join Date: Dec 2014
Posts: 4
supremegrandruler is on a distinguished road
Default Macro not running on exiting legacy drop down menu.

I have a simple drop down menu and right-cliked it -> Exit and selected my macro (posted below). But when I select an item from the menu, nothing happens.

Code:
Public Sub Test1()
    With ActiveDocument.Content.Find
        .Text = "BOLD"
        .MatchWildcards = True
        .MatchCase = True
        .Replacement.Font.Bold = True
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Reply With Quote
  #2  
Old 12-10-2014, 03:17 PM
macropod's Avatar
macropod macropod is offline Macro not running on exiting legacy drop down menu. Windows 7 64bit Macro not running on exiting legacy drop down menu. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

There is nothing wrong with the macro, as such. Without knowing how you're using your dropdown menu, though, it's impossible to say what the issue is. If you're referring to a dropdown formfield, the only macro one of those can run is the one specified in it's properties as the 'exit' macro. your macro security settings would also have to allow macros to run.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-11-2014, 06:47 AM
supremegrandruler supremegrandruler is offline Macro not running on exiting legacy drop down menu. Windows 7 32bit Macro not running on exiting legacy drop down menu. Office 2007
Novice
Macro not running on exiting legacy drop down menu.
 
Join Date: Dec 2014
Posts: 4
supremegrandruler is on a distinguished road
Default

I can run the macro just fine by clicking "Macros -> Run MyMacro".

I'm using a legacy drop down field. I right clicked it and selected MyMacro in the "Exit" field. I protect the document to "Filling in forms" so I can start using the drop down. Then I select a value from the drop down menu but nothing happens.
Reply With Quote
  #4  
Old 12-11-2014, 08:17 AM
gmayor's Avatar
gmayor gmayor is offline Macro not running on exiting legacy drop down menu. Windows 7 64bit Macro not running on exiting legacy drop down menu. Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

In order for the macro to be able to do anything in a protected form, you are going to have to include code to unprotect (and reprotect) the form. In your example:

Code:
Public Sub Test1()
Dim bProtected As Boolean
    'Unprotect the file
    If ActiveDocument.ProtectionType <> wdNoProtection Then
        bProtected = True
        ActiveDocument.Unprotect Password:=""
    End If
    With ActiveDocument.Content.Find
        .Text = "BOLD"
        .MatchWildcards = True
        .MatchCase = True
        .Replacement.Font.Bold = True
        .Execute Replace:=wdReplaceAll
    End With
    If bProtected = True Then
        ActiveDocument.Protect _
                Type:=wdAllowOnlyFormFields, _
                NoReset:=True, _
                Password:=""
    End If
End Sub
and note that your macro was called Test1 and not MyMacro ! Run Test1 on exit from the field. On Exit means when you leave the field, not when you select an item.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 12-11-2014, 09:18 AM
supremegrandruler supremegrandruler is offline Macro not running on exiting legacy drop down menu. Windows 7 32bit Macro not running on exiting legacy drop down menu. Office 2007
Novice
Macro not running on exiting legacy drop down menu.
 
Join Date: Dec 2014
Posts: 4
supremegrandruler is on a distinguished road
Default

Thanks. It works save for one thing: it only bolds "BOLD" when it's not located in a drop down menu. I want it to bold also the word "BOLD" even in drop down menus.
Reply With Quote
  #6  
Old 12-11-2014, 11:14 PM
gmayor's Avatar
gmayor gmayor is offline Macro not running on exiting legacy drop down menu. Windows 7 64bit Macro not running on exiting legacy drop down menu. Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You cannot embolden only the word BOLD in a dropdown form field, unless you convert the field result to plain text (whereupon it will no longer be a form field). You can however embolden the whole field range if the dropdown result contains the world BOLD e.g.

Code:
Public Sub Test1()
Dim bProtected As Boolean
Dim oFld As FormField
    If ActiveDocument.ProtectionType <> wdNoProtection Then
        bProtected = True
        ActiveDocument.Unprotect Password:=""
    End If
    With ActiveDocument.Content.Find
        .Text = "BOLD"
        .MatchWildcards = True
        .MatchCase = True
        .Replacement.Font.Bold = True
        .Execute Replace:=wdReplaceAll
    End With
    For Each oFld In ActiveDocument.FormFields
        If InStr(1, oFld.Result, "BOLD") > 0 Then
            oFld.Range.Font.Bold = True
        Else
            oFld.Range.Font.Bold = False
        End If
    Next oFld
    If bProtected = True Then
        ActiveDocument.Protect _
                Type:=wdAllowOnlyFormFields, _
                NoReset:=True, _
                Password:=""
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro not running on exiting legacy drop down menu. HELP -- Drop Menu for Reoccuring Data?? cscaudle Word 1 03-02-2014 10:19 AM
Drop down menu with different value to display name swsquish Word 1 09-04-2012 08:45 PM
Adding Macro menu to the right click menu (Word 2007) masam123 Word 0 10-14-2011 04:05 AM
Macro will not save to normal.dot file when exiting bobbraun Word 1 09-28-2010 06:26 AM
Merge fields & Drop down menu's ShadeTree Word 0 03-09-2010 08:19 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:12 AM.


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