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 / June 2007

Tip: Looking for answers? Try searching our database.

Howto get and set the current caret position?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SvenC - 19 Jun 2007 08:50 GMT
Hi,

in the MVP FAQ I found how to get the current page and can also use the GoTo
method to jump to any page.
But I would like to get the exact current caret position before I close a
document so that later I can set the caret if I open the document again.
Can that be done?

--
SvenC
Shauna Kelly - 19 Jun 2007 12:30 GMT
Hi SvenC

You can get information about the cursor position through
Application.Selection.Range.Information(). Look up VBA's help for all the
parameters that .Information can take and what they return.

However, there's no need to save the information. When you open a Word
document, do Shift-F5. That returns the insertion point to where it was when
you saved the document. You can achieve the same thing in VBA using
   Application.GoBack

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

> Hi,
>
[quoted text clipped - 6 lines]
> --
> SvenC
SvenC - 19 Jun 2007 14:44 GMT
Hi Shauna,

> Hi SvenC
>
[quoted text clipped - 6 lines]
> was when you saved the document. You can achieve the same thing in
>    VBA using Application.GoBack

Neither Shift+F5 nor GoBack is working for me in Word 2007. I tried this
VBA:

sFile = ActiveDocument.FullName
ActiveDocument.Close
Set odoc = Application.Documents.Open(sFile)
Application.GoBack

But the document is opened with the beginning shown, no movement by calling
GoBack or pressing Shift+F5

The Information Method was how I got the current page, but unfortunately it
is not giving the current line, only the line relative to the page.
But when I use Goto, to go to an absolute page and from there to a relative
line the caret is always position on the absolute line from the beginning.

I was able to take the Selection Start and End properties and use
oDoc.Range(start, end).Select to position the insertion mark correctly. Now
only the scrolling position is not as before. I can get the scrolling
postion of the current window in percent but unfortunately the document is
loaded step by step so right after the Documents.Open call the scrolling bar
is not exact as the document and its statistics (number of pages,
characters...) is loaded in the background.

But with the insertion point being correct it is quite OK for me.

Thanks,
SvenC
 
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.