Open Writer File with a macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Newbie Tom
Posts: 3
Joined: Thu Aug 14, 2008 11:03 pm

Open Writer File with a macro

Post by Newbie Tom »

Colleagues,

I presume this question will reveal me as an utter newbie.
I have many standardized documents that I use again and again and I would like to be able to call them up with a click on a macro button.

I have repeatedly tried to record the macro "File/Open/ThisDirectory/ThatDocument." But the recorder stops when the new document opens.

I can record an "Insert File" command, but I'm concerned that I will lose some of the automation built into the standard docs.
If I edit the "InsertFile" macro with "Open," the directory will open. If I replace "InsertDoc" with "OpenDoc" or "OpenFile" or any other variation I can think of, nothing happens.

What on earth am I doing wrong?

Thanks,
Tom
OOo 2.4.X on Ms Windows XP
User avatar
Hagar Delest
Moderator
Posts: 32654
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Open Writer File with a macro

Post by Hagar Delest »

Does it help: [Solved] Macro similar to "OpenDocument" & "SaveAs"?

Thanks to add '[Solved]' at beginning of your first post title (edit button) if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Newbie Tom
Posts: 3
Joined: Thu Aug 14, 2008 11:03 pm

Re: Open Writer File with a macro

Post by Newbie Tom »

Thank you, but these do not quite solve the problem.
I want to be able to open a specific file from within a directory.

This macro will insert a file into an open document:

Code: Select all

sub TransferAndLicense
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:InsertDoc", "", 0, Array())

rem ----------------------------------------------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Name"
args2(0).Value = "file:///C:/Documents%20and%20Settings/TJH/Desktop/Forms%20Library/Equipment%20Transfer%20and%20License.doc"
args2(1).Name = "Filter"
args2(1).Value = "MS Word 97"

dispatcher.executeDispatch(document, ".uno:InsertDoc", "", 0, args2())


end sub
How do I open that "Equipment Transfer and License" document as a NEW document?

Many thanks,
Tom
OOo 2.4.X on Ms Windows XP
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Open Writer File with a macro

Post by JohnV »

Or perhaps this for a specific file.

Code: Select all

Sub OpenDoc
Dim  url
url = ConvertToURL("c:\MyDoc.odt")
StarDesktop.loadComponentFromURL(url,"_blank",0,Array())
End Sub
User avatar
Hagar Delest
Moderator
Posts: 32654
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Open Writer File with a macro

Post by Hagar Delest »

And why don't you make templates from those files? They've to be saved as .ott files (better use the File>Organize>Save dialog for that).
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Newbie Tom
Posts: 3
Joined: Thu Aug 14, 2008 11:03 pm

Re: Open Writer File with a macro

Post by Newbie Tom »

My thanks to JohnV and Hagar!

Is there a reference or documentation I should have to help me with these questions?

Tom
OOo 2.4.X on Ms Windows XP
User avatar
Hagar Delest
Moderator
Posts: 32654
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Open Writer File with a macro

Post by Hagar Delest »

See that thread: [Solved] Writing Macros - Where Do I Start?

Thanks to add '[Solved]' at beginning of your first post title (edit button) if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Post Reply