| View previous topic :: View next topic |
| Author |
Message |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Wed Jun 22, 2005 11:29 am Post subject: Selected address to envelope & print envelope |
|
|
This macro will copy & paste the addressee’s address that you have selected in a letter to an envelope and print the envelope. My limited testing indicates that it will work with a simple typed address, an address made up of data source fields or one made up of user fields.
It assumes you have:
1) Created an envelope template file that works correctly with your printer.
2) That this template contains an empty text frame intended to hold the recipient's address and that the name of the frame is “Addressee” (this is the default name of the appropriate frame in an envelope created using Insert > Envelope when you choose the New Doc option), and
3) That you will edit the macro to provide the correct path to your envelope template.
EDITED 6-23-05 to allow user to enter the address directly in the envelope if no address is selected, i.e., the envelope is just opened and the macro quits.
| Code: | Sub SelectedAddressToEnvelope
On Error goto ErrorHandler
oDoc = thisComponent
oVC = oDoc.CurrentController.getViewCursor
If oVC.String = "" then
NoSelection = true
msg = "Nothing has been selected. Do you want to type the address "
msg = msg & "directly in the envelope or quit?"
iAns = MsgBox (msg,1,"NO SELECTED ADDRESS.")
If iAns = 2 then End
EndIf
envURL = ConvertToURL("c:\docs\Envelope.stw") 'Path to envelope template.
If NOT FileExists(envURL) then
MsgBox "Unable to locate your envelope template at the URL '" & envURL & "'. Quitting!"
End
EndIf
oFrame = oDoc.CurrentController.Frame
oENV = StarDeskTop.loadComponentFromUrl(envURL,"_blank",0,Array())
oEnvVC = oEnv.CurrentController.getViewCursor
oTFrames = oEnv.getTextFrames()
oAddrFrame = oTFrames.getByName("Addressee")
oEnvTC = oAddrFrame.createTextCursor
oEnvVC.gotoRange(oEnvTC,false)
If NoSelection then END 'Let user complete and print envelope.
oEnvFrame = oEnv.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(oFrame, ".uno:Copy", "", 0, Array())
dispatcher.executeDispatch(oEnvFrame, ".uno:Paste", "", 0, Array())
iAns = MsgBox ("Ready to print?",1,"PRINT ENVELOPE")
If iAns = 2 then End
oPrinter = oEnv.getPrinter()
oEnv.Print(oPrinter) : END 'Normal program end.
ErrorHandler:
If err# = 1 then
msg = "Unable to find text frame named 'Addressee'. Quitting!"
ElseIf err# = 423 then msg = "Some document must be open. Quitting!"
Else msg = "An unknown error has occurred. Error #" & err# & " Quitting!"
EndIf
MsgBox (msg,,"A MACRO ERROR OCCURED!")
End Sub |
|
|
| Back to top |
|
 |
Oropi Newbie

Joined: 14 Aug 2005 Posts: 3
|
Posted: Sun Aug 14, 2005 8:16 am Post subject: Nicely done |
|
|
Great macro that comes in very handy.
Just a question though, is there a way to change the macro to PASTE the address into the ADDRESSEE field in PASTE UNFORMATTED form? For some reason I loose formatting of the template as the PASTE function of the source overrides the template.
Cheers,
Oropi |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Mon Aug 15, 2005 9:59 am Post subject: |
|
|
Try substituting these lines:
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "SelectedFormat"
args2(0).Value = 1
dispatcher.executeDispatch(oEnvFrame, ".uno:ClipboardFormatItems", "", 0, args2())
for this line:
dispatcher.executeDispatch(oEnvFrame, ".uno:Paste", "", 0, Array()) |
|
| Back to top |
|
 |
Oropi Newbie

Joined: 14 Aug 2005 Posts: 3
|
Posted: Mon Aug 15, 2005 10:21 am Post subject: |
|
|
GREAT stuff.
Works like a charm.
Many thanks,
Oropi |
|
| Back to top |
|
 |
gokee2 Newbie

Joined: 30 Nov 2007 Posts: 4
|
Posted: Fri May 15, 2009 4:57 pm Post subject: Re: Nicely done |
|
|
| Oropi wrote: | Great macro that comes in very handy.
Just a question though, is there a way to change the macro to PASTE the address into the ADDRESSEE field in PASTE UNFORMATTED form? |
I would also like to paste unformatted.
Another thing, can it be made to work in calc as well as writer?
Thanks! |
|
| Back to top |
|
 |
|
|
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
|