OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Macros and Bookmarks

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer
View previous topic :: View next topic  
Author Message
Ildebrando
General User
General User


Joined: 06 Feb 2005
Posts: 8

PostPosted: Sun Feb 06, 2005 12:36 am    Post subject: Macros and Bookmarks Reply with quote

While using Word I had made two macros which were very useful to me, as I usually work on long documents.

The first macro created a bookmark called "here", overwriting it if it already existed; I launched it to mark the place where I was working in the document, for example before browsing it in search of something.

The second macro, called "go_to_here", made the cursor jump to the bookmark previously created, thus leading me back to where I was before.

They were two very simple macros, created with the recording method, but they were very effective and useful.

I seem to be unable to recreate the trick in Writer.
The first macro works only the first time; then it fails to overwrite the previous bookmark "here" and creates a new one called "here1" and then "here2", "here3" and so on.
I also tried two create two separate macros, one to remove the bookmark and one to create it again, but nothing better happens.

As to the other macro, it simply does not work at all, as if it were impossibile, in Writer, to create a simple macro which moves the cursor to a bookmark.

Is there anything I can do to achieve what I need?

Thanks.
Back to top
View user's profile Send private message
8daysaweek.co.uk
Super User
Super User


Joined: 29 Nov 2003
Posts: 2130
Location: UK

PostPosted: Sun Feb 06, 2005 9:25 am    Post subject: Re: Macros and Bookmarks Reply with quote

Ildebrando wrote:
While using Word I had made two macros which were very useful to me, as I usually work on long documents.

The first macro created a bookmark called "here", overwriting it if it already existed; I launched it to mark the place where I was working in the document, for example before browsing it in search of something.

The second macro, called "go_to_here", made the cursor jump to the bookmark previously created, thus leading me back to where I was before.


I am not sure about how to get macros to do what you want, but opening the file at the point last edited is the default behaviour anyway, so you shouldn't need to recreate those macros.

The option is set here: Tools > Options > OpenOffice.org > View > Under Restore > Editing view.

HTH Smile,
_________________
James
www.8daysaweek.co.uk - A User-Focused OOo site
Back to top
View user's profile Send private message Visit poster's website AIM Address
Ildebrando
General User
General User


Joined: 06 Feb 2005
Posts: 8

PostPosted: Sun Feb 06, 2005 9:38 am    Post subject: Reply with quote

Well, I knew that opening the file at the point last edited is the default behaviour anyway.
However that would force me to close and reopen every time I need to jump somewhere in the document (for example to check whether I already wrote something or not) and then get back where I was writing.
Of course I can live without my macros, but having them back would be better. It seems impossible to me that OOo is not able to do such a simple thing, really much simpler than many others it does very well.

Thanks for your answer anyway.
Back to top
View user's profile Send private message
8daysaweek.co.uk
Super User
Super User


Joined: 29 Nov 2003
Posts: 2130
Location: UK

PostPosted: Sun Feb 06, 2005 9:47 am    Post subject: Reply with quote

Ildebrando wrote:
However that would force me to close and reopen every time I need to jump somewhere in the document (for example to check whether I already wrote something or not) and then get back where I was writing.

Embarassed Sorry, I hadn't understood your problem/question correctly. I will give it some more thought. Hopefully someone may already have a solution, or will come up with one Smile
_________________
James
www.8daysaweek.co.uk - A User-Focused OOo site
Back to top
View user's profile Send private message Visit poster's website AIM Address
8daysaweek.co.uk
Super User
Super User


Joined: 29 Nov 2003
Posts: 2130
Location: UK

PostPosted: Mon Feb 07, 2005 1:53 pm    Post subject: Reply with quote

I've now tried to record macros to create then find a bookmark, and run into the same problem you had.

I assume you are familiar with the Navigator, which will take you straight to a bookmark you've created with a macro - regardless of what name is assigned to it - just by double-clicking on it Question
I 'dock' the navigator to the left hand side of the window so that all parts of my document are within easy reach.

The other workaround I thought of - and tried - is to insert some unique text into the document using a macro e.g. [~~bookmark~~] and create another macro to find then delete this text. Not as neat as using a real bookmark, but it works for me.

HTH Smile,
_________________
James
www.8daysaweek.co.uk - A User-Focused OOo site
Back to top
View user's profile Send private message Visit poster's website AIM Address
Iannz
OOo Advocate
OOo Advocate


Joined: 14 Feb 2004
Posts: 494
Location: Christchurch, New Zealand

PostPosted: Mon Feb 07, 2005 7:59 pm    Post subject: Reply with quote

The following macros are not thoroughly tested but I think they should work.
Code:
sub subSetTempBookmark
const TempBookmarkName = "IannzHere"
oDoc = thisComponent
oBookmarks = oDoc.bookmarks
if oBookmarks.hasByName(TempBookmarkName) then
   oBookmarks.getByName(TempBookmarkName).dispose
end if
oVC = oDoc.currentController.viewCursor
oBookmark = oDoc.createInstance("com.sun.star.text.Bookmark")
oBookmark.Name = TempBookmarkName
oVC.Text.insertTextContent(oVC, oBookmark, True)
end sub


sub subJumpToTempBookmark
const TempBookmarkName = "IannzHere"
oDoc = thisComponent
oVC = oDoc.currentController.viewCursor
oBookmarks = oDoc.bookmarks
if oBookmarks.hasByName(TempBookmarkName) then
   oVC.gotoRange(oBookmarks.getByName(TempBookmarkName).anchor, false)
end if
end sub

_________________
Cheers, Ian

http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions.


Last edited by Iannz on Mon Feb 07, 2005 10:37 pm; edited 1 time in total
Back to top
View user's profile Send private message
Ildebrando
General User
General User


Joined: 06 Feb 2005
Posts: 8

PostPosted: Mon Feb 07, 2005 10:23 pm    Post subject: Reply with quote

Thanks a lot, Iannz.

Your macros seem to work pretty well (I should learn some programming, lazy me!).
I tested them in a long document of mine and everything went well.
However, when I closed that document and loaded another one, something happened:
when launching the first macro (subSetTempBookmark) I got the following error message:

An exception occurred.
Type: com.sun.star.uno.RuntimeException
Message: text interface and cursor not related

Do you have any idea about the reason?

Thanks again for your precious help.
Back to top
View user's profile Send private message
Iannz
OOo Advocate
OOo Advocate


Joined: 14 Feb 2004
Posts: 494
Location: Christchurch, New Zealand

PostPosted: Mon Feb 07, 2005 10:40 pm    Post subject: Reply with quote

Embarassed The problem was, probably, that in the second document you were running the macro with the cursor in a table (or not in the main document anyway).
I have edited the code in my original post. The change is the last line of the first macro:
Code:
oVC.Text.insertTextContent(oVC, oBookmark, True)
end sub

_________________
Cheers, Ian

http://wiki.services.openoffice.org/wiki/Extensions_development_basic a wiki about writing OpenOffice.org extensions.
Back to top
View user's profile Send private message
Ildebrando
General User
General User


Joined: 06 Feb 2005
Posts: 8

PostPosted: Tue Feb 08, 2005 11:22 am    Post subject: Reply with quote

Well Ian,

what can I say?
Thanks a lot, you simply solved my problem completely!

Hope to be able to do the same for you one day
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group