#1
|
|||
|
|||
if next key pressed is "del"
I want to add code to a macro that will:
if next key pressed is "del", will press del key and restart macro |
#2
|
||||
|
||||
Perhaps you could explain what the macro is doing. How do you propose the macro should sit in a state where it is waiting for a keypress event?
It sounds like you should be using a MsgBox to ask the user if they want to delete something.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
if next key pressed is "del"
The macro is below. It highlights the next set of square brackets when I press + (the closest key to the mouse which was free to reassign). Essentially, it replaces Dragon Dictate verbal commands which require me to turn on the mic when I prefer to keep it off and talk while editing).
If I want to change the text that is highlighted I type in the change, press + and go to the next set of []. If I want to keep the default text I press + and go to the next set of [....default text]. If I want to delete highlight and move on to the next set of [] want to add code that will: If the next key pressed is "del" press "del" and run the macro again (to continue to the next set of []. this is my code: Sub FindBetweenSqBrac() ' ' FindBetweenSqBrac Macro ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "(\[)(*)(\])" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute End Sub Thank you. |
#4
|
||||
|
||||
The simplest way is to use a MsgBox to ask if the user wants to continue on to the next location. You can click Yes (or type Y) to find next or No (or type N) to stop the macro. If you want to change the text, you type N to end the macro, make the desired change and then start the macro again.
Code:
Sub FindNextSquareBrackets() Dim iResp As Integer, aRng As Range Set aRng = ActiveDocument.Range(Selection.Range.Start, ActiveDocument.Range.End) With aRng.Find .ClearFormatting .Replacement.ClearFormatting .Text = "(\[)(*)(\])" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True Do While .Execute aRng.Select iResp = MsgBox("Goto Next?", vbYesNo, "Found one") If iResp = vbNo Then Exit Sub aRng.Collapse Direction:=wdCollapseEnd aRng.End = ActiveDocument.Range.End Loop End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
if next key pressed is delete
Thanks. I had already considered your approach. The problem is that it slows down the work when there are many [default text] in the document
would this work? Sub FindBetweenSqBrac() ' ' FindBetweenSqBrac Macro ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "(\[)(*)(\])" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute If the next key pressed is {DEL} then SendKeys {DEL} play FindBetweenSqBrac Macro OR if the next key pressed is anything else than {DEL} then End Sub Or would reassigning keypresses work? for example: run FindBetweenSqBrac Macro 'same code as macro above then assign {DEL} to "{DEL} and run FindBetweenSqBrac macro" then assign {DEL} back to {DEL} End Sub Thanks again Savvy |
#6
|
|||
|
|||
next key pressed is del
Thanks so much Guessed.
I tried your suggestion and it works perfectly. I am trying to tweak it to work in the context of the task I am doing. I have assigned the macro to an unused key sequence. 1) can I change the behavior of hitting "N" to: if after I type a word or sentence, when I next press enter, the macro would play again instead of starting a new line, and revert to its normal behavior? 2) how do I change the code to respond to keypress " ' " instead of "N", then revert " ' " back to " ' "? Thanks Savvy |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mailto Hyperlink Formula contains too large of "Body" receiving "#Value" need to find workaround | MCamera | Excel | 1 | 03-02-2022 07:52 PM |
Excel 2003: VBA "Function" causes "#VALUE!" errors after running "insert/delete row" custom macro | Matt C | Excel Programming | 2 | 01-08-2022 06:03 AM |
How to configure Word 10 so that when "enter" is pressed, the entire next line of text drops togethe | JKW | Word | 3 | 11-25-2015 04:55 PM |
remove repeated words with " macro " or " wild cards " in texts with parentheses and commas | jocke321 | Word VBA | 2 | 12-10-2014 11:27 AM |
How to choose a "List" for certain "Heading" from "Modify" tool? | Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |