|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Returning to the pane (and maybe point) that the cursor was when the macro started
I apologize if this is too simple. I'm new at this.
I have a macro that changes all text in the main document, header, and footer to Times New Roman font (see below). At the end, it goes to the end of the main document. I would rather it go back to whatever pane was active when the macro started. Even better would be for it to go back to the exact point the cursor was at when it started. I tried lots of variations on setting dimensions of myvariable to various options, then tried setting myvariable=ActiveWindow.ActivePane.View or ActiveWindow.ActivePane.View.SeekView, etc., then at the end of the macro, ActiveWindow.ActivePane.View.SeekView = myhvariable But whatever specific variable type and syntax I need, I couldn't find. Please help. Sub TNR() ' ' Change all fonts to Times New Roman ' ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument Selection.WholeStory Selection.Font.Name = "Times New Roman" ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader Selection.WholeStory Selection.Font.Name = "Times New Roman" ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter Selection.WholeStory Selection.Font.Name = "Times New Roman" ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument Selection.EndOf End Sub |
#2
|
||||
|
||||
You can either set a range at the start and select the range at the end e.g.
Code:
Dim oRng As Range Set oRng = Selection.Range ' 'Do stuff ' ' oRng.Select Code:
Sub TNR() Dim oStory As Range For Each oStory In ActiveDocument.StoryRanges oStory.Font.Name = "Times New Roman" If oStory.StoryType <> wdMainTextStory Then While Not (oStory.NextStoryRange Is Nothing) Set oStory = oStory.NextStoryRange oStory.Font.Name = "Times New Roman" Wend End If Next oStory lbl_Exit: Set oStory = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Side topic, this would be far better if done through styles.
|
#4
|
|||
|
|||
Do you mean something like this Charles:
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oStyle As Style For Each oStyle In ActiveDocument.Styles On Error Resume Next oStyle.Font.Name = "Times New Roman" Next oStyle lbl_Exit: Exit Sub End Sub There probably aren't that many more Word users that knows what a style is, than knows how to map a CC |
#5
|
|||
|
|||
Greg, yes that is what I mean.
As to your other point, I would guess that about 30 times as many know what a style is as know how to map a CC. Unfortunately, even the number who know what styles are is likely less than 50%. (At least who know more than that they can click on a button on the Home tab.) IMO, mapping CCs is advanced while using effectively using styles is intermediate. Styles should be basic and mapping CCs should be intermediate. Our experiences on the forums give a skewed view of user skills and knowledge, I suspect. |
Tags |
pane view variable |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
excel macro returning the wrong value | anne.kiss@ntlworld.com | Excel Programming | 7 | 03-14-2019 05:53 AM |
OneNote Undo: Insertion point/cursor "jumps" when typing Ctrl+Z | aspiringgeek | OneNote | 0 | 03-21-2017 07:23 PM |
Cursor location on first click -- insertion point | stevec5088 | Word | 1 | 12-14-2016 02:45 PM |
Cursor in reading pane | Danny DeLoach | Outlook | 2 | 08-16-2011 11:58 AM |
A macro to mirror the movement of the cursor | ACA | Word VBA | 0 | 08-24-2010 03:21 PM |