Return to original cursor position, efter executing macro?

E

Eric G

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
 
G

Greg

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
 
G

Greg

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
 
J

Jonathan West

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


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
 
J

Jonathan West

Greg said:
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
 
E

Eric G

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top