| View previous topic :: View next topic |
| Author |
Message |
Cosmic P OOo Enthusiast

Joined: 23 Mar 2005 Posts: 186
|
Posted: Wed Apr 13, 2005 4:30 am Post subject: Jump to bookmark? |
|
|
I'm trying to build a macro that, when the user wants to print out a file, checks if all the essential data has been filled out. If something's missing (like the user's name), the visible cursor should jump to it.
The following code didn't work:
| Code: | oViewCursor = ThisComponent.CurrentController.getviewCursor()
oBookmark = ThisComponent.Bookmarks.getByName("your_name").Anchor
oViewCursor.gotorange(oBookmark, false) |
The second line produced the exception $arg1) |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Wed Apr 13, 2005 5:51 am Post subject: |
|
|
try to select the object with the current controller. Something like:
| Code: | | ThisComponent.getCurrentController().select(object) | Try selecting that text range... _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
Cosmic P OOo Enthusiast

Joined: 23 Mar 2005 Posts: 186
|
Posted: Wed Apr 13, 2005 10:09 pm Post subject: |
|
|
What do I put in the select()-command?
| Code: | | ThisComponent.getCurrentController().select("your_name") |
A similar problem: I want to insert a text at a bookmark, but the following code doesn't work. It produces the same exception as the one above:
| Code: | | ThisComponent.getBookmarks().getByName("MyBookmark").getAnchor.setString("Input this text here") | [/code] |
|
| Back to top |
|
 |
Peter OOo Enthusiast

Joined: 28 May 2004 Posts: 105 Location: Berlin / Germany
|
Posted: Wed Apr 13, 2005 11:46 pm Post subject: |
|
|
Not tested:
oViewCursor = ThisComponent.CurrentController.getviewCursor()
sBookmark = "your_name"
oRange = BookmarkJumping(ThisComponent,sBookmark)
oViewCursor.gotoRange(oRange, false)
oViewCursor.String = "MyString"
Function BookmarkJumping(Doc,sBookmark) as Object
oBookmark = Doc.Bookmarks.GetByName(sBookmark)
BookmarkJumping = oBookmark.Anchor.Text.CreateTextCursorByRange(oBookmark.Anchor)
End Function
Keep in mind, that a bookmark is always a range, you can select text and then insertt the bookmark.
Peter |
|
| Back to top |
|
 |
Cosmic P OOo Enthusiast

Joined: 23 Mar 2005 Posts: 186
|
Posted: Thu Apr 14, 2005 4:13 am Post subject: |
|
|
OK, I've found the problem: a simple typing error in the name.
So far I can use the methods setString en getString, but I can not type at the bookmarkt directly.
After executing the procedure, I see the visible cursor at the bookmark for a fraction of a second, then it's gone and I can not type. |
|
| Back to top |
|
 |
Peter OOo Enthusiast

Joined: 28 May 2004 Posts: 105 Location: Berlin / Germany
|
Posted: Thu Apr 14, 2005 10:30 pm Post subject: |
|
|
With my posted code I can type immediately, if you want to modify the range, don't use oViewCursor.String but oRange.String =
Peter |
|
| Back to top |
|
 |
|