# macro with if condition

I have an autoopen macro to go on a specif bookmark ("here") created whenever I save a writer document. I wonder if it could be possible to disable this macro if the odt file is open from another odt file (and not from Dolphin, i.g.). So I could open the target file at the point I want (a bookmark different from "here").
Thanks

EDIT

@Lupp: 1) autoopen: I mean that macro runs automatically when a odt is opened

2) this is the macro (stored, so to say, not in a file, but in LibreOffice: affecting all odt files)

sub vai_qui

If ThisComponent.supportsService("com.sun.star.text.TextDocument") Then

oBookmarks = ThisComponent.getBookmarks()
If NOT oBookmarks.hasByName("qui") Then
Exit Sub
End If

ViewCursor = ThisComponent.CurrentController.getviewCursor()
Bookmark = ThisComponent.Bookmarks.getByName("qui").Anchor
ViewCursor.gotorange(Bookmark, False)

ViewCursor = ThisComponent.CurrentController.getviewCursor()
Bookmark = ThisComponent.Bookmarks.getByName("qui").Anchor
ViewCursor.gotorange(Bookmark, False)

else
Exit Sub
End If
end sub


3) I'd like add a code, if possible, to disable this macro (in the target-document) if the new document is open (not from a specific file, but) from inside LibreOffice (/LibreWriter) and not from "outside" (i.g. Dolphin). Thank you

edit retag close merge delete

The subject you chose seems misleading to me. Conditional statements in macros are surely well known.
In your case the question is how to branch in a macro called for an opening document anyway based on info about what/who had opened it.
I also don't know the term "autoopen macro" as something with a clear meaning.

( 2020-02-18 12:26:36 +0100 )edit

Sort by » oldest newest most voted

You did neiter tell where the "autoopen" macro is located and how it is called nor in what way the second document should be opened "from another odt file". Will there run user code? Is the document linked? If so ...
Please give the needed details next time! We may run in time-waste otherwise.

Assuming you want to call the second document by a macro running for another one:
The macro in charge of going to a specific bookmark may choose it based on information passed by the macro opening the documnt. I don't know a standardized way to pass caller info, but you can set the .Title property by the calling macro and evaluate it by the onViewCreated macro of the opened one. .Title neither is readonly nor is it saved with the document.

Example code lines:

doc2Url    = ConvertToUrl("full file path to my second document")
doc2       = StarDeskTop.loadComponentFromUrl(doc1Url, "_blank", 0, Array())
doc2.Title = doc2.Title & "?openedby=WizardMacro"

more