Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-17-2024, 02:52 AM
RRB's Avatar
RRB RRB is offline Document specific macros Windows 11 Document specific macros Office 2021
Susan Flamingo
Document specific macros
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 263
RRB is on a distinguished road
Default Document specific macros

Hi friends!



Is it a sin to store a macro and it hotkey trigger in the document level as opposed to the template?

What I am puzzled with is that I have a group of macros that are basically the same function but vary slightly from doc to doc. I want to assign the same hotkey to the macros to execute the macro that is meant for that specific doc. But hotkey-macro connections are stored in at the template level so this will not work correctly for each doc.
Maybe my whole methodology is mistaken here...

Sincerely, a confused flamingo

Update edit:

I thought I could do an if statement getting the title property of the document and executing the macro as desired for each doc.
Reply With Quote
  #2  
Old 03-17-2024, 12:10 PM
Charles Kenyon Charles Kenyon is online now Document specific macros Windows 11 Document specific macros Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

You certainly can store macros and hotkeys both in documents.

If your macros are in your documents and you store your hotkey globally but the macro is in the same module with the same name in each document, the hotkey should trigger the macro in the document rather than a globally stored macro.
See:
If you use a global template for the shortcut, there should be a macro stored in the global template that will respond to it if there is not a macro in the document.


If I were doing this, though, I would not put a separate macro in each document, but rather use a document variable in the document and have a central macro that performs the action and varies according to the presence and value of that variable.

Chris Woodman's Keyboard Shortcut Organizer contains a utility to let you read, set, and modify document variables from within the user interface, without going to the vba editor. Chris Woodman's Keyboard Shortcut Organizer
Reply With Quote
  #3  
Old 04-01-2024, 11:34 AM
TessaMurillo TessaMurillo is offline Document specific macros Windows Vista Document specific macros Office 2010
Advanced Beginner
 
Join Date: Mar 2024
Posts: 33
TessaMurillo has a little shameless behaviour in the past
Default

Storing macros and their hotkey triggers at the document level can have its benefits. One approach to solving your problem might be to use a macro that will assign a hotkey depending on the document. You can use the document's Title property to determine which macro to assign to a hotkey.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run macros when document opens THH4929 Word VBA 2 05-27-2018 01:26 AM
Document specific macros Use Macros to add a new row in protected document cepdance Word VBA 6 01-04-2017 08:18 AM
Document specific macros Word document with Macros with trusted locatin versus Word document 1997-2003 Cardinal2 Word 1 11-30-2015 07:42 PM
Document specific macros 5 Macros in One Document--Question rsrasc Word VBA 4 10-31-2014 05:10 AM
Document specific macros Discover if Macros exist in template or document jimbassett Excel 2 02-08-2010 08:06 AM

Other Forums: Access Forums

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