Discussion:
Return to original cursor position, efter executing macro?
(too old to reply)
Eric G
2005-08-31 13:46:00 UTC
Permalink
Windows XPP SP2
Office Professional 2003 SP1



Hello,

I'm writing documents in 9 different languages. I've Office Proofing Tools 2003, installed for all languages.

In Word, I experience that sometimes, often when text is copied between various documents, the default document language change for a paragraph, or two. I've created some simple macros that sets the complete document language to the language I require and they all work fine. The macros simply selects the entire document, then sets the language, e.g. "Swedish" and when finished executing, the cursor position finishes up at the end of the document.

Is there a way, so to say, to anchor, or for the cursor to return to its original cursor position, where it was positioned, when macro was started after the macro is executed?

Below is a sample of my simple macros.

Sub Select_Entire_Document_SE()
'
' Select_Entire_Document_SE Macro
' Macro recorded 6/12/2004 by EG
'
Selection.WholeStory
Selection.LanguageID = wdSwedish
Selection.NoProofing = False
Application.CheckLanguage = True
Selection.EndKey Unit:=wdStory
End Sub

I would be grateful for any suggestions.

Eric G
Stockholm, Sweden
Greg
2005-08-31 14:15:33 UTC
Permalink
You could add bookmark at the IP. Do your thing, go back to the
bookmark then delete it:

Sub Select_Entire_Document_SE()

With Selection
.Bookmarks.Add ("Origin")
.WholeStory
.LanguageID = wdSwedish
.NoProofing = False
End With
Application.CheckLanguage = True
With Selection
.EndKey Unit:=wdStory
.GoTo What:=wdGoToBookmark, Name:="Origin"
End With
ActiveDocument.Bookmarks("Origin").Delete


End Sub
Greg
2005-08-31 14:15:34 UTC
Permalink
You could add bookmark at the IP. Do your thing, go back to the
bookmark then delete it:

Sub Select_Entire_Document_SE()

With Selection
.Bookmarks.Add ("Origin")
.WholeStory
.LanguageID = wdSwedish
.NoProofing = False
End With
Application.CheckLanguage = True
With Selection
.EndKey Unit:=wdStory
.GoTo What:=wdGoToBookmark, Name:="Origin"
End With
ActiveDocument.Bookmarks("Origin").Delete


End Sub
Jonathan West
2005-08-31 14:17:12 UTC
Permalink
Hi Eric,

This will do the trick. Add the two lines at the start and the one line at
the end to any macro where you want to restore the original cursor position

Sub Select_Entire_Document_SE()
'
' Select_Entire_Document_SE Macro
' Macro recorded 6/12/2004 by EG
'
Dim myRange as Range
Set myRange = Selection.Range
Selection.WholeStory
Selection.LanguageID = wdSwedish
Selection.NoProofing = False
Application.CheckLanguage = True
Selection.EndKey Unit:=wdStory
myRange.Select

End Sub
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org


"Eric G" <***@microsoft.com> wrote in message news:***@TK2MSFTNGP12.phx.gbl...
Windows XPP SP2
Office Professional 2003 SP1



Hello,

I'm writing documents in 9 different languages. I've Office Proofing Tools
2003, installed for all languages.

In Word, I experience that sometimes, often when text is copied between
various documents, the default document language change for a paragraph, or
two. I've created some simple macros that sets the complete document
language to the language I require and they all work fine. The macros simply
selects the entire document, then sets the language, e.g. "Swedish" and when
finished executing, the cursor position finishes up at the end of the
document.

Is there a way, so to say, to anchor, or for the cursor to return to its
original cursor position, where it was positioned, when macro was started
after the macro is executed?

Below is a sample of my simple macros.

Sub Select_Entire_Document_SE()
'
' Select_Entire_Document_SE Macro
' Macro recorded 6/12/2004 by EG
'
Selection.WholeStory
Selection.LanguageID = wdSwedish
Selection.NoProofing = False
Application.CheckLanguage = True
Selection.EndKey Unit:=wdStory
End Sub

I would be grateful for any suggestions.

Eric G
Stockholm, Sweden
Greg
2005-08-31 14:22:10 UTC
Permalink
Jonathan,

Yeah. Much better :-)
Jonathan West
2005-08-31 14:31:04 UTC
Permalink
Post by Greg
Jonathan,
Yeah. Much better :-)
Of course, better still is to avoid modifying the selection position in the
first place if you can, by using Range objects instead of the selection.
Here is the same macro rewritten that way.

Sub Select_Entire_Document_SE()
'
' Select_Entire_Document_SE Macro
' Macro recorded 6/12/2004 by EG
'

ActiveDocument.Range.LanguageID = wdSwedish
ActiveDocument.Range.NoProofing = False
Application.CheckLanguage = True

End Sub
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Eric G
2005-08-31 15:42:58 UTC
Permalink
Dear Jonathan and Greg,

It's so easy - when you know how to do it!

I am most grateful to both of you for your assistance. I took Jonathan's suggestion, implemented it, and off it went. Perrrfect!

Once again, thank you.

Regards,



Eric G,
Stockholm Sweden

"Eric G" <***@microsoft.com> wrote in message news:***@TK2MSFTNGP12.phx.gbl...
Windows XPP SP2
Office Professional 2003 SP1



Hello,

I'm writing documents in 9 different languages. I've Office Proofing Tools 2003, installed for all languages.

In Word, I experience that sometimes, often when text is copied between various documents, the default document language change for a paragraph, or two. I've created some simple macros that sets the complete document language to the language I require and they all work fine. The macros simply selects the entire document, then sets the language, e.g. "Swedish" and when finished executing, the cursor position finishes up at the end of the document.

Is there a way, so to say, to anchor, or for the cursor to return to its original cursor position, where it was positioned, when macro was started after the macro is executed?

Below is a sample of my simple macros.

Sub Select_Entire_Document_SE()
'
' Select_Entire_Document_SE Macro
' Macro recorded 6/12/2004 by EG
'
Selection.WholeStory
Selection.LanguageID = wdSwedish
Selection.NoProofing = False
Application.CheckLanguage = True
Selection.EndKey Unit:=wdStory
End Sub

I would be grateful for any suggestions.

Eric G
Stockholm, Sweden

Loading...