Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-01-2017, 08:11 AM
StephenRay StephenRay is offline Consolidate 25 Macros Into One, Too Many Hot Keys! Windows 7 64bit Consolidate 25 Macros Into One, Too Many Hot Keys! Office 2010 64bit
Advanced Beginner
Consolidate 25 Macros Into One, Too Many Hot Keys!
 
Join Date: Jan 2012
Location: Overland Park, Kansas
Posts: 53
StephenRay is on a distinguished road
Default Consolidate 25 Macros Into One, Too Many Hot Keys!

If it is possible, I want to learn to consolidate about 25 Macros that I presently run by 25 different Hot Keys. I have all the Hot Keys memorized. I usually run these in a certain order but sometimes I go back and run one out of the usual sequence.
I envision one consolidated Macro where …once it is started, Macro1 would run displaying a Message box, …Then when a Hot Key, (or the Enter Key), is depressed, Macro2 would run, displaying a Message Box, …Then that same Hot Key, depressed again, it would cause Macro3 to run displaying another Message box, …and so on through the 25 Macros. A button in the Message box would be convenient to do the same thing as that same hot key.
I also envision during this process that if one of the original 25 different Hot Keys, is depressed, it would cause the sequence to go out order, directly to the Macro associated with that unique Hot Key whereupon a Message Box would appear; -and where the sequence/loop would then start from that place!
The Message Box would show the operator something like:
“Name is on the clipboard: Joe Jones.” Or
“Address is on the clipboard: 811 Walnut Street.”
I don’t really need the message box, I am thinking the appearance of a Message Box is the only way to pause, is that right? Presently, each separate Macro highlights the text on the clipboard in the Active document so I can glance at it to be sure I have grabbed the right thing to the clipboard.
These 25 macros are usually simple, finding text and combining complicated texts in a Microsoft Word Document and highlighting a name or address or other text, putting it on the clipboard, ready to be pasted to another application, Microsoft Active Directory, on another screen while I am using dual screens.
A couple of these Macros open another document, find some text based on what is already on the clipboard, -then highlights and gets different text on the clipboard, then closes that document, making the original document the active document. The last Macro in the sequences does a Save AS, Closes the Active Document, changes the directory, and opens a document ready for the cycle to begin again.
What say you? Is it possible to combine my 25 Macros into one big Macro and traverse through it sequentially or go to a certain part of it?
Here’s an example of one of these Macros, a very simple one that gets the name to the clipboard:
Sub Macro17()
' Macro17 Macro
'Name
'This part clears the clipboard
Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.SetText ""
clipboard.PutInClipboard
Dim oRng As Range
‘The name is always on the second line
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
‘This next part gets the spaces out
Set oRng = Selection.Range
oRng.Text = Trim(oRng.Text)
oRng.Copy
ActiveDocument.Undo 1 'Put the spaces back in the text.
'Highlights the text so the operator can see what is on the clipboard
Selection.EndKey Unit:=wdLine, Extend:=wdExtend


Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End Sub
Reply With Quote
  #2  
Old 08-01-2017, 10:47 AM
gmaxey gmaxey is online now Consolidate 25 Macros Into One, Too Many Hot Keys! Windows 7 32bit Consolidate 25 Macros Into One, Too Many Hot Keys! Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Something like this perhaps:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 8/1/2017
Dim lngIndex As Long
Dim strMacro As String
  lngIndex = 1
  Do
    Select Case lngIndex
      Case 1: Macro_1
      Case 2: Macro_2
      Case 3: Macro_3
      Case 4:
        Macro_4
        'This is the last macro
        Exit Do
    End Select
    strMacro = InputBox("Macro " & lngIndex & " complete. Enter the next macro number or click ok", "Next Macro", "Ok")
      If strMacro = "Ok" Then
        lngIndex = lngIndex + 1
      Else
        lngIndex = CLng(strMacro)
      End If
      
    Loop
lbl_Exit:
  Exit Sub
End Sub
Sub Macro_1()
  'Whatever
End Sub
Sub Macro_2()
  'Whatever
End Sub
Sub Macro_3()
  'Whatever
End Sub
Sub Macro_4()
  'Whatever
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-01-2017, 10:49 AM
StephenRay StephenRay is offline Consolidate 25 Macros Into One, Too Many Hot Keys! Windows 7 64bit Consolidate 25 Macros Into One, Too Many Hot Keys! Office 2010 64bit
Advanced Beginner
Consolidate 25 Macros Into One, Too Many Hot Keys!
 
Join Date: Jan 2012
Location: Overland Park, Kansas
Posts: 53
StephenRay is on a distinguished road
Default

gmaxey, Thank you for your reply. I will study this.
Reply With Quote
  #4  
Old 08-02-2017, 05:42 AM
StephenRay StephenRay is offline Consolidate 25 Macros Into One, Too Many Hot Keys! Windows 7 64bit Consolidate 25 Macros Into One, Too Many Hot Keys! Office 2010 64bit
Advanced Beginner
Consolidate 25 Macros Into One, Too Many Hot Keys!
 
Join Date: Jan 2012
Location: Overland Park, Kansas
Posts: 53
StephenRay is on a distinguished road
Default

gmaxey, This looks ingenious! But I'm starting to get burnt out, I have been studying so hard on all this. It may be a week or so before I work with this. Thanks!
Reply With Quote
  #5  
Old 08-03-2017, 11:36 AM
StephenRay StephenRay is offline Consolidate 25 Macros Into One, Too Many Hot Keys! Windows 7 64bit Consolidate 25 Macros Into One, Too Many Hot Keys! Office 2010 64bit
Advanced Beginner
Consolidate 25 Macros Into One, Too Many Hot Keys!
 
Join Date: Jan 2012
Location: Overland Park, Kansas
Posts: 53
StephenRay is on a distinguished road
Default

gmaxey,
Is it true, with your code, -to choose the next macro number, the operator would do one of these:
A. use the keyboard to enter one or two number and click the OK Button.
B. use the keyboard to enter one or two number and depress the ENTER KEY.

Either way is ok; because sometimes my hands are situated to use the mouse and sometimes the keyboard is quicker.

But it would be even better if the Input Box, (or Dialog Box), would allow a Shortcut Key, something like:
Ctrl + x or Alt + x or Ctrl + Shift + x
Ctrl + a or Alt + a or Ctrl + Shift + a
Ctrl + b or Alt + b or Ctrl + Shift + b
about 25 different ones like this!

Because I can keep my little finger on the Ctrl Button by habit. And then to depress only one other key is as faster than you can say USS Gerald R. Ford.

This may sound silly, but when I get in a good rhythm, depressing three keys instead of just one seems very cumbersome and slow as molasses. And a required mouse-click when my hands are flat on the keyboard seems cumbersome indeed.

I have been looking and I can't find any way to do this. Perhaps you know of a way.

Last edited by StephenRay; 08-03-2017 at 12:57 PM. Reason: add something
Reply With Quote
  #6  
Old 08-03-2017, 01:17 PM
gmaxey gmaxey is online now Consolidate 25 Macros Into One, Too Many Hot Keys! Windows 7 32bit Consolidate 25 Macros Into One, Too Many Hot Keys! Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

No, none of those combinations are possible because the inputbox does not recognize Ctrl or Alt.

You could use Shift+a, Shift+b, ...

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 8/1/2017
Dim lngIndex As Long
Dim strMacro As String
  lngIndex = 1
  Do
    Select Case lngIndex
      Case 1: Macro_1
      Case 2: Macro_2
      Case 3: Macro_3
      Case 4:
        Macro_4
        'This is the last macro
        Exit Do
    End Select
    strMacro = InputBox("Macro " & lngIndex & " complete. Enter the next macro number or click ok", "Next Macro", "Ok")
      Select Case strMacro
        Case "Ok"
        lngIndex = lngIndex + 1
      Case Else
       lngIndex = Asc(strMacro) - 64
      End Select
      
    Loop
lbl_Exit:
  Exit Sub
End Sub
Sub Macro_1()
  'Whatever
End Sub
Sub Macro_2()
  'Whatever
End Sub
Sub Macro_3()
  'Whatever
End Sub
Sub Macro_4()
  'Whatever
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 08-04-2017, 05:52 AM
StephenRay StephenRay is offline Consolidate 25 Macros Into One, Too Many Hot Keys! Windows 7 64bit Consolidate 25 Macros Into One, Too Many Hot Keys! Office 2010 64bit
Advanced Beginner
Consolidate 25 Macros Into One, Too Many Hot Keys!
 
Join Date: Jan 2012
Location: Overland Park, Kansas
Posts: 53
StephenRay is on a distinguished road
Default

gmaxey, There's not that much difference between ctrl and shift. I can take that. Thanks.
I did not notice this in my reading in my book. I will go home and look for Shift in connection with InputBox.

As for your logic where you subtract 64, I think I get it. In the ASCII table, there are 64 other symbols before the alphabet in the table. So I have to align my macro number with this in mind.

Last evening I had given up trying to find HotKeys and Shortcut Keys in connection with an Input Box & Dialog Box Response.
So I was reading about Dialog Boxes in my book, searching, searching for a way. And I found something. KEYPRESS. Ctrl can be used with KEYPRESS but only when using a User Form Object, my book says. Of course, this is way over my head right now. But I will work up to it.
Fancy Dialog Boxes and User Form look very easy compared to trying to figure out VBA Syntax.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Consolidate 25 Macros Into One, Too Many Hot Keys! Macros to move objects prevents moving same objects with arrow keys BruceM Word VBA 1 03-10-2015 08:20 AM
Consolidate Pivots linked to SQL mtayloripf Excel 0 02-11-2014 08:16 AM
Consolidate 25 Macros Into One, Too Many Hot Keys! How Find Out What Keys Trigger My Macros? peytontodd Word 1 10-28-2013 09:39 AM
Consolidate 25 Macros Into One, Too Many Hot Keys! Consolidate names jgross30 Excel 7 05-13-2013 08:36 PM
Is it possible to bind macros to keys not in the KeyCodeConstants class? AlexR Word VBA 4 04-08-2013 10:15 AM

Other Forums: Access Forums

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