PDA

View Full Version : Stuck with Highlighting Macro



pjraisman
09-01-2016, 02:06 AM
Hi there,

I´m trying to implement a Macro in Word that will let me select the highlighter tool without having selected a word first. When I do it using the mouse, the mouse´s pointer will change its shape to the following one:
16984
Esentially i want to replicate the same thing through VBA. Does anyone know if it´s possible?

For now the only function I´ve found is "Selection.Range.HighlightColorIndex = wdBrightGreen", which forces you to modify the actual selection.

Thanks!
Pedro

gmayor
09-01-2016, 04:50 AM
Why would you need to do that with a macro when Word has a built-in function to do that?
If you want to highlight text with a macro then select the text or set a range to the text in question and highlight it.

pjraisman
09-01-2016, 07:09 AM
Why would you need to do that with a macro when Word has a built-in function to do that?
If you want to highlight text with a macro then select the text or set a range to the text in question and highlight it.

That's a logical question. The reason is I have a Wacom digital tablet (the kind graphic designers and digital artists use) and I would like to use it to review documents (highlighting, drawing, scribbling on them, etc...). The tablet software allows to reprogram the existing buttons in the tablet to any key combination of choice. The idea is to create a Macro, assign to it a key combination, and then assign one of the tablet's button to that key combination. The idea is that one button would be for example "yellow highlight" another ", "orange highlight" , "red pen" etc...I wan't to be able to change colours and type of pen (highlighter, normal pen, eraser, etc..) very quickly without having to drag the cursor up to the ribbon or menus each time.

gmayor
09-01-2016, 09:12 PM
You would need to create macros to highlight the selected text in whatever colour you wish along the lines of the code segment in your original message and apply a shortcut which you suggest can be addewd to your device - http://www.gmayor.com/installing_macro.htm

pjraisman
09-02-2016, 03:29 AM
You would need to create macros to highlight the selected text in whatever colour you wish along the lines of the code segment in your original message and apply a shortcut which you suggest can be addewd to your device -

Thanks for your answer Graham, but as I was mentioning in my opening post, I´m not looking to highlight text which has been previously selected, but to activate the selection tool without having previously selected anything. I have managed to solve ths issue with a less than elegant solution which I´m explaining below in case anyone´s interested.

Steps:

1). I´ve created the following script using Autohotkey program which is freeware (first result in google). The script just sends the key combination of "ALT+h+i" and "Enter" which is the key combo to activate the highlighter.

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
send !h
send i
send {enter}
Return

2) I´ve compiled the script code to an executable EXE file using Autohotkey´s included compiler

3) I´ve created the following macro in VBA word and assigned it to the F4 key. Essentially it just runs the script in the background while keeping the focus of the active window on Word (to ensure the key combination takes place within the program)

Sub RunYellowHighlighter()
Dim result As Double
Dim sFullPathToExecutable As String
sFullPathToExecutable = "C:\Users\Desktop\Myscript.exe"
Application.ScreenUpdating = False
result = Shell(sFullPathToExecutable, windowstyle:=vbHide)
Application.ScreenUpdating = True
End Sub

4) I´ve gone to my Wacom Tablet software and assigned one of the buttons directly to F4.


The solution works fine, although there would be two improvements to make:

-Avoid using the hotkeys program and send the keys combo directly from VBA, cutting the middleman

-Make the process transparent as screenupdating doesn´t seem to do anything in this case and you can still see the ribbon moving from one tab to the other and the highlighter dropdown expanding.

gmaxey
09-02-2016, 07:56 AM
I think this would avoid the middleman:


Sub ScratchMacro()
SendKeys "%+h+i{enter}"
End Sub