#1
|
|||
|
|||
Simulate a key press (left arrow)
Hello there! I am trying to make a Macro to simulate a single key press (left arrow, in this case); just that key press and stop. Why this? Well, I have an AutoOpen macro that reads like this:
Sub AutoOpen() ' ' AutoOpen Macro ' ' This macro opens itself (AutoOpen) automatically with every Word document that's opened normally ' Choose background colour (light green 2) ActiveDocument.Background.Fill.ForeColor.ObjectThe meColor = wdThemeColorAccent6 ActiveDocument.Background.Fill.ForeColor.TintAndSh ade = 0.6 ActiveDocument.Background.Fill.Visible = msoTrue ActiveDocument.Background.Fill.Solid ' Turn option 'Show background colors and images in Display view' on ActiveWindow.View.DisplayBackgrounds = True ' Select all text and change font to black colour Selection.WholeStory Selection.Font.Color = wdColorBlack End Sub Now what does it do? First, it chooses the background colour to be light green 2, and then turns the option to show background colors on, this makes it so that every already-created word document that is opened is opened with a green background (as new ones were already created green because I changed the display). Now the second thing is the important one: select all text and change the colour of the font to black, this is because the documents I'm being given are coloured in grey, which is not so optimal. Therefore, I made this macro in AutoOpen so that all text is selected and then all text is changed to black. The problem is, when this ends, it ends with all the text being selected still, which means I don't have the cursor at the start as I should. This is solved, manually, by pressing left arrow, which makes the cursor go to the start, so that's why I want this keypress. If anyone knows how to do this, any help is appreciated. Just in case, I am just a novice in VBA/Macros, I just fiddled a bit with some codes I found around internet and suited them to my needs, very very roughly. Thank you. |
#2
|
|||
|
|||
It is very rare that you need to select anything when using VBA code. Here is your routine rewritten to avoid selecting the text.
Code:
Sub AutoOpen() ' ' AutoOpen Macro ' ' This macro opens itself (AutoOpen) automatically with every Word document that's opened normally ' Choose background colour (light green 2) With ActiveDocument.Background.Fill .ForeColor.ObjectThe meColor = wdThemeColorAccent6 .ForeColor.TintAndSh ade = 0.6 .Visible = msoTrue .Solid End With ' Turn option 'Show background colors and images in Display view' on ActiveWindow.View.DisplayBackgrounds = True ' Select all text and change font to black colour ActiveDocument.Content.Font.Color = wdColorBlack End Sub |
#3
|
|||
|
|||
Quote:
|
Tags |
key presses |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
TOC goes into update after using the QAT back button or Alt and left arrow key to return | craigt | Word | 7 | 01-30-2023 05:45 AM |
left - right arrow keys don't function properly | natanzel | Word | 1 | 06-27-2017 04:38 AM |
Problem with [Ctrl] + [Left Arrow] in Word 2010 (32bit) | alxx86 | Word | 4 | 03-03-2016 07:22 AM |
Why does the circular and U Turn arrow only go left to right? | Cerdic | PowerPoint | 1 | 10-22-2013 07:16 PM |
Left arrow won't work on Word | LaBecs | Word | 2 | 09-26-2011 09:27 AM |