Open Writer File with a macro

Creating a macro - Writing a Script - Using the API

Open Writer File with a macro

Postby Newbie Tom » Thu Aug 14, 2008 11:12 pm

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
Newbie Tom
 
Posts: 3
Joined: Thu Aug 14, 2008 11:03 pm

Re: Open Writer File with a macro

Postby Hagar Delest » Thu Aug 14, 2008 11:52 pm

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.
AOO 4.1.6 on Xubuntu 19.04 and 4.1.5 on Windows 7 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 28543
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Open Writer File with a macro

Postby Newbie Tom » Fri Aug 15, 2008 12:51 am

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   Expand viewCollapse view
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
Newbie Tom
 
Posts: 3
Joined: Thu Aug 14, 2008 11:03 pm

Re: Open Writer File with a macro

Postby JohnV » Fri Aug 15, 2008 12:54 am

Or perhaps this for a specific file.
Code: Select all   Expand viewCollapse view
Sub OpenDoc
Dim  url
url = ConvertToURL("c:\MyDoc.odt")
StarDesktop.loadComponentFromURL(url,"_blank",0,Array())
End Sub
JohnV
Volunteer
 
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Open Writer File with a macro

Postby Hagar Delest » Fri Aug 15, 2008 12:57 am

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).
AOO 4.1.6 on Xubuntu 19.04 and 4.1.5 on Windows 7 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 28543
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Open Writer File with a macro

Postby Newbie Tom » Mon Aug 18, 2008 4:15 pm

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
Newbie Tom
 
Posts: 3
Joined: Thu Aug 14, 2008 11:03 pm

Re: Open Writer File with a macro

Postby Hagar Delest » Sat Aug 30, 2008 10:42 pm

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.
AOO 4.1.6 on Xubuntu 19.04 and 4.1.5 on Windows 7 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 28543
Joined: Sun Oct 07, 2007 9:07 pm
Location: France


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 8 guests