Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2017, 10:31 AM
PellePetimeter PellePetimeter is offline Start macro when placeholder gets focus Windows 10 Start macro when placeholder gets focus Office 2016
Novice
Start macro when placeholder gets focus
 
Join Date: Mar 2017
Posts: 3
PellePetimeter is on a distinguished road
Default Start macro when placeholder gets focus

I want to create a macro that starts when a placeholder gets focus or gets changed. I have googled it but found nothing. Isn't this possible?



We use Word 2016.
Reply With Quote
  #2  
Old 03-14-2017, 07:32 PM
macropod's Avatar
macropod macropod is offline Start macro when placeholder gets focus Windows 7 64bit Start macro when placeholder gets focus 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

That's quite easy if your placeholder is a formfield (in a document with forms protection), content control or ActiveX control serving as the placeholder, but not otherwise. What is your placeholder?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-15-2017, 01:41 AM
PellePetimeter PellePetimeter is offline Start macro when placeholder gets focus Windows 10 Start macro when placeholder gets focus Office 2016
Novice
Start macro when placeholder gets focus
 
Join Date: Mar 2017
Posts: 3
PellePetimeter is on a distinguished road
Default

It is at content control.
Reply With Quote
  #4  
Old 03-15-2017, 05:26 AM
macropod's Avatar
macropod macropod is offline Start macro when placeholder gets focus Windows 7 64bit Start macro when placeholder gets focus 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

In that case, you'd use a Document_ContentControlOnEnter macro to the Document's 'ThisDocument' code module. The skeletal structure is:
Code:
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)

End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-16-2017, 01:50 AM
PellePetimeter PellePetimeter is offline Start macro when placeholder gets focus Windows 10 Start macro when placeholder gets focus Office 2016
Novice
Start macro when placeholder gets focus
 
Join Date: Mar 2017
Posts: 3
PellePetimeter is on a distinguished road
Default

It works, thanks!
But this macro starts each time any content control gets focus. So I need to either change the code so it just starts when a specific content control is marked or do something like:

Code:
Private Sub Document_ContentControlOnEnter(ByVal CC As ContentControl)
If CC.Title like "Leder" Then doSomeThing
End Sub
It's been i while since I worked with macros so it's not stright forward to me, but I'll figuere it out.
Reply With Quote
  #6  
Old 03-16-2017, 04:26 AM
macropod's Avatar
macropod macropod is offline Start macro when placeholder gets focus Windows 7 64bit Start macro when placeholder gets focus 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

Yes, if you want to restrict the response to one or more content controls, you need to specify which one(s) to act on or to exclude. That can be done via the content control's Title and/or Tag, or its relative position in a defined range (i.e. Document, Section, Table, etc.).

There are plenty of examples of that on this forum, though usually in the context of a ContentControlOnExit macro. A search for 'ContentControl' will turn up numerous examples.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
macro in word, placeholder



Similar Threads
Thread Thread Starter Forum Replies Last Post
Start macro when placeholder gets focus Macro to move focus after entry in a cell Phil H Excel Programming 3 06-18-2015 01:20 PM
difference between scheduled start and start ketanco Project 3 01-15-2015 07:53 AM
Start macro when placeholder gets focus SlideMaster: Date Placeholder, Footer Placeholder, Slide Number Placeholder? tinfanide PowerPoint 1 04-05-2013 10:37 AM
Should be a simple macro, need a start Jamtart PowerPoint 7 08-13-2012 06:11 AM
automatic start of macro + help on writing helper function vsempoux Word 3 10-09-2009 03:01 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:14 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