Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

Return to original cursor position, efter executing macro?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eric G - 31 Aug 2005 14:46 GMT
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 - 31 Aug 2005 15:15 GMT
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 - 31 Aug 2005 15:15 GMT
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 - 31 Aug 2005 15:17 GMT
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

Signature

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
Greg - 31 Aug 2005 15:22 GMT
Jonathan,

Yeah.  Much better :-)
Jonathan West - 31 Aug 2005 15:31 GMT
> 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

Signature

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 - 31 Aug 2005 16:42 GMT
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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.