Word Merge (OpenInsight 32-Bit)
At 05 FEB 2007 05:55:14PM Barry Stevens wrote:
I have a word merge template, I want to be able to *run* this template to create a designated output .doc file.
Can I do this via say runwin by passing parameters or is there a new *bob way* using his ocx stuff.
At 06 FEB 2007 01:45PM [url=http://www.sprezzatura.com]The Sprezzatura Group[/url] wrote:
You can easily do it by invoking winword with the /Mmacroname parameter and running a macro which does it. We've just done this to great effect on an AREV system and a combination of CMD and START makes the process invisible to the user. They choose the AREV menu option and a neatly formatted Word report appears on the printer. Making it a Doc would be a very simple modification.
World leaders in all things RevSoft
At 06 FEB 2007 01:49PM [url=http://www.sprezzatura.com]The Sprezzatura Group[/url] wrote:
and yes you can easily do it with OLE (and yes we do know we owe a white paper on this - we'll put it in the next SENL which is due in a few weeks).
World leaders in all things RevSoft
At 06 FEB 2007 04:58PM Bob Carten wrote:
Thanks Sprezz. And Sprezz
My mail_merge approach has been to use an rlist callback function to generate a CSV file, then OLE calls to open a template, attach my csv file as the data source, then merge. I'm sure Sprezz will put out a clearly explained example.
I have been fooling around with saving MsWord documents as XML, hacking the XML as plain text, then using ShellExecute with Print to print the result. I suspect that with a little fiddling you can accomplish what you want with osread, swap, oswrite, shellexecute.
Similarly I recently saved an MsAccess report as XML. MsAccess created an XSL template for the report, a matching XML data file, then used the Microsoft XMLDOM object to transform the data using the XSLT. I replaced their XML data with my OI generated data, ran the XSLT transform, generated a report. An interesting way to get OIPI-like functionality without using any OLE. Would work on Windows or Linux, no need for presentation server.
- Bob
At 06 FEB 2007 06:36PM Warren Auyong wrote:
We write out a CSV file, and shellexecute an Excel template which has an autorun macro in it that sucks in the CSV then autosaves itself as another spreadsheet and that gets emailed out with all the nice column formating and headers in the original.
Same sort of deal I suppose.
At 07 FEB 2007 09:13AM John Bouley wrote:
We wrote a utility that creates a csv file then using OLE and shellExecute opens word, opens the document, and initiates a WordMerge. Basically, I transalated a VB merge automation routine into OI OLE.
HTH,
John
At 07 FEB 2007 04:59PM Barry Stevens wrote:
This is what I have done and it works:
hWnd=0
lpOperation=open':\00\
lpFileName=WINWORD":\00\
lpParams=/f ":quote(DocPathFileName):" /MMailMergeToDoc":\00\
lpDir=\00\
iShow=1
retVal=ShellExecuteA(hWnd,lpOperation,lpFileName,lpParams,lpDir,iShow)
The csv file will only contain a single record.
What I want to be able to do is specify what the merged doc name is as opposed to the default letter1. I could not find a msword param to do this.
I cannot workout the ole methods my self.
At 08 FEB 2007 09:24AM John Bouley wrote:
Barry,
My application creates a sample csv file with the first row containing the fields names and up to 10 rows of sample data. Then the user opens the document and sets up the merge files. Basically, pointing the data source to the sample csv. Then the user places the merge fields in the document. They can then preview the 10 records using Word. If everything is correct they save the document and close Word.
Finally, using OI OLE and shellexecute the merge process is automated… The whole utility is part of a library that I charge for.
John
At 08 FEB 2007 12:31PM Bob Carten wrote:
Barry,
from MsWord Help
command line witches
/ttemplatename
Start Word with a new document based on a template other than the Normal template (Normal template: A global template that you can use for any type of document. You can modify this template to change the default document formatting or content.). Example: /tMyfax.dot
Note If the file name has spaces in it, enclose the complete name in quotation marks for example, /t"Elegant Report.dot"
does that do it?
At 08 FEB 2007 04:36PM Barry Stevens wrote:
John, email me at [email protected] with price and more details
At 08 FEB 2007 05:07PM Barry Stevens wrote:
Bob
I saw that, but I dont understand how it can
At 09 FEB 2007 08:22AM Bob Carten wrote:
Barry
Does this help?
- Bob
pre.code {
background-color: #E5E5E5;border: 1px solid #000000;width: 640px;padding: 5px;font-family: courier, verdana, arial, serif;margin: 0px 10px auto;}
Subroutine Ole_Word_Example4(byVal_MainDoc, byVal_DataDoc, byVal_print_flag, byVal_visible_Flag ) /* Use OLE and MailMerge to print a word document argMainDoc=full path to the source document Procedure will copy it to a temp location so multiple users do not get 'document in use errors' argDataDoc=full path to the data source Procedure assumes data is a temp file, so deletes the datafile upon completion. print_flag=boolean, tr If print_flag is true, then the document prints, word will close If print_flag is false, then after the merge the result will show on the screen so the user can edit it visible_Flag=Boolean, true to show the document Usage: - Create a word MailMerge Document, add merge fields where you want to place data from OI columns - Create a program which will generate a CSV file whenever the user wants to print a document. Put the file in a user-specific location to allow concurrent printing * ----------------------------------------------------------- 09-23-2006 rjc Created */ Declare function Dialog_Box, get_Property declare function GetTempFilename, GetTempPath Declare subroutine set_status $Insert Msg_Equates $Insert logical $insert Dict_Equates equ crlf$ to \0D0A\ equ tab$ to \09\ MainDoc =if assigned(byVal_MainDoc) then byVal_MainDoc else '' DataDoc =if assigned(byVal_DataDoc) then byVal_DataDoc else '' print_flag =if assigned(byVal_print_flag) then not(not(byVal_print_flag)) else false$ visible_Flag =if assigned(byVal_visible_Flag) then not(not(byVal_visible_Flag)) else not(print_flag) err=' begin case case dir(Maindoc)<2> < 1 err=Invalid Word Document' case dir(Datadoc)<2> < 1 err=Invalid Data Document' end case if err then set_status(1, err) return '' end *--- * Use a copy of the document else multiple users get 'file in use' error * Could use a template too *--- osread document from Maindoc else document=' err=Invalid Word Document' set_status(1, err) return '' end filename=Maindoc-1,'B\' buffer=space(256) ret=GetTempPath(len(buffer), buffer) path=buffer1,ret IF path-1,1=\' else path := '\' targetfile=path:filename oswrite document on targetfile * * Open the temp copy * oWrd=OleCreateInstance("Word.Application") OlePutProperty(oWrd,'Visible', -1) oDocuments=oleGetProperty(oWrd, 'Documents') oDoc=OleCallMethod(oDocuments, 'OPEN', targetfile) oWrd->visible=visible_flag * * Perform the merge * oMerge=oDoc->MailMerge oMerge->SuppressBlankLines=True$ oMerge->MainDocumentType=0 oDataSource=oMerge->OpenDataSource( Datadoc, 0, False$, True$, True$, False$, "", "", False$, "", "", "", "", "") oDataSource->FirstRecord=1 // wdDefaultFirstRecord oDataSource->LastRecord=-16 //wdDefaultLastRecord x=oMerge->Execute(True$) * Get handle for the merge output * Note Arrow syntax fails for properties with arguments, must spell out OleGetProperty oMergeOut=OleGetProperty(oDocuments, 'Item', 1) * Close the template, we only need the result x=oDoc->Close() * ASSUME that if you print it is OK to Close, else you want to leave the doc open for the * user to edit If print_flag then x=oMergeOut->PrintOut( False$) x=oMergeOut->Close( False$) x=oWrd->Quit(False$) end else oWrd->Visible=true$ end * Delete data file, temp file OsDelete DataDoc OsDelete targetfile return ''
At 09 FEB 2007 10:50AM [email protected] wrote:
cool .. but stop using that ugly 'made for oi' shorthand
At 09 FEB 2007 12:45PM Pascal Landry wrote:
I love that shorthand, I think it's one of the greatest thing since sliced bread!
At 09 FEB 2007 01:43PM Don Muskopf wrote:
I'm with DSig. Please, let's not use shorthand in programming examples. I may be slow upstairs, but trust me, for those of us who never use shorthand, it's not short when you have to take time to translate the shorthand to understand the code. :)
At 09 FEB 2007 10:57PM Barry Stevens wrote:
Fantastic!
]]09-23-2006 rjc Created
So you have bag of ole tricks up your sleeve
OK, Where do I make a donation to the Carten pension fund
At 09 FEB 2007 11:55PM Barry Stevens wrote:
Bob,
Without you 'creating a rod for your own back', is it possible for you to specify the name (and path if possible) of the merged output document.
highly appreciated,
-Barry
ps: can I have your email address -] [email protected]
At 11 FEB 2007 08:39PM Bob Carten wrote:
Barry -
The best way to customize these OLE scripts is to turm on the macro recorder in MS Word, walk through the process you want to automate, then tramslate the resulting macro to Basic+. In fact, the reason I use the shorthand syntax is that it often maps 1:1 between Visual Basic for Applications (VBA) and Basic+. I cut from VBA, paste to OI, swap . for -] , then fix it from there. Another trick is to use the VBA editor's immediate window to determine tbe value of any constants.
For example, the VBA script might show wdDefaultFirstRecord. You type ?wdDefaultFirstRecord in the immediate window and VBA will tell you that the value is 1.
Bob
At 11 FEB 2007 11:07PM Barry Stevens wrote:
I am really sorry but…I think I have problems as i dont know VBA.
When you get a chance, can you look at this. I have it at the end of your code to rename the merged output document.
Macro:
ChangeFileOpenDirectory "C:\"
ActiveDocument.SaveAs FileName:=This a test for.doc", FileFormat:= _wdFormatDocument, LockComments:=False, Password:=", AddToRecentFiles:= _True, WritePassword:=", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _False, SaveNativePictureFormat:=False, SaveFormsData:=False, _SaveAsAOCELetter:=FalseMe:
oActiveDoc=oDoc-]ActiveDocument
FileName=C:\This a test.doc"
ActiveDocument=oActiveDoc-]SaveAs(FileName,False$,False$,"",True$,"",False$,False$,False$,False$,False$)
TYIA
Barry
At 12 FEB 2007 11:11AM Bob Carten wrote:
I'll e-mail you.
Bob