Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-30-2020, 08:04 PM
MrConfused MrConfused is offline Returning to the pane (and maybe point) that the cursor was when the macro started Windows 10 Returning to the pane (and maybe point) that the cursor was when the macro started Office 2010
Novice
Returning to the pane (and maybe point) that the cursor was when the macro started
 
Join Date: Sep 2020
Posts: 1
MrConfused is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 09-30-2020, 08:24 PM
gmayor's Avatar
gmayor gmayor is offline Returning to the pane (and maybe point) that the cursor was when the macro started Windows 10 Returning to the pane (and maybe point) that the cursor was when the macro started Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
or use ranges and don't move the selection e.g.
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
Reply With Quote
  #3  
Old 10-03-2020, 10:45 AM
Charles Kenyon Charles Kenyon is offline Returning to the pane (and maybe point) that the cursor was when the macro started Windows 10 Returning to the pane (and maybe point) that the cursor was when the macro started Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Side topic, this would be far better if done through styles.
Reply With Quote
  #4  
Old 10-03-2020, 01:55 PM
gmaxey gmaxey is online now Returning to the pane (and maybe point) that the cursor was when the macro started Windows 10 Returning to the pane (and maybe point) that the cursor was when the macro started Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 10-06-2020, 04:53 AM
Charles Kenyon Charles Kenyon is offline Returning to the pane (and maybe point) that the cursor was when the macro started Windows 10 Returning to the pane (and maybe point) that the cursor was when the macro started Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
Reply

Tags
pane view variable

Thread Tools
Display Modes


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
Returning to the pane (and maybe point) that the cursor was when the macro started Cursor location on first click -- insertion point stevec5088 Word 1 12-14-2016 02:45 PM
Returning to the pane (and maybe point) that the cursor was when the macro started 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

Other Forums: Access Forums

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