Running & executing Winword Macro From OI (OpenInsight Specific)
At 09 MAR 1999 05:18:10AM David Schranz wrote:
I am Linking with Word and executing a Macro Created in Word.
The Problem is that when I come to install the OI product at a client site I do not wish to have to copy the Normal.dot file (where the Macro is stored in Word in my opinion) onto the Word Directory as I will overwrite any other Macros created by the Client. But I wish that when I call the DDELink from OI, I inform Word to run the Macro from within a file in my directory not in the directory of Word.
An Suggestions ?
At 10 MAR 1999 03:22AM Bob Watson wrote:
You should create a new template in Word to contain your macros, ship the template with your ap and then run the template and macros when required.
Bob Watson
At 14 MAR 1999 04:19AM Anders Lindholt wrote:
Dear David,
Have a look in my code, - it may help you. It's copy a dot file form dotfile area, open og move data via dde link to book marks in word doc.
You can seach on 'WORD´on the web.
Best regards
Anders
Here's the code.
declare function repository, send_message, utility, popup, msg, send_event
DECLARE subroutine copy_file, S_ADD_KAL
$insert openlaw
Equate Yes$ to 0
*
* skriv buffer til disk
*
flush
garbagecollect
retv = utility("CURSOR","H")
win = @window
ActiveChild=Get_property("MDI", "MDIACTIVE")
Open
,'SETUP' to f.setup else call msg(@window,'Fatal fejl ej open af SETUP tabel, tilkald systemadministrator') end children = utility('OBJECTLIST',"MDI","WINDOW") id = get_property('CHILD_CASE.CASE_ID_FIX','TEXT') IF ID =
THEN id = CASES@to =
navn = "" tabel_arr = "" p = "" pop = "" Delete_flag=Yes$ init = abb@ starttid = time() to =
*
*
setup = xlate("SETUP","NR","","X")
focus_case = get_property('CHILD_CASE','FOCUS')
begin case
case focus_case=CHILD_CASE.INFO_KEY'case_rowd = get_property('CHILD_CASE.INFO_KEY','ROWDATA')to = case_rowdcase focus_case=CHILD_CASE.LIST_PERSONER'row = get_property('CHILD_CASE.LIST_PERSONER','DEFPROP')info_arr = get_property('CHILD_CASE.INFO_KEY','ARRAY')pos = get_property('CHILD_CASE.LIST_PERSONER','SELPOS')POSS = POSfor x=1 to 15case_rowd=info_arrnext xend case
WP_SERVICE = SETUP
wp_path = setup
wp_type = setup
wp_name = setup
wp_dot = setup
wp_btid =setup
wp_bookm = setup
pp = ""
*
*
navnet = GET_PROPERTY(@WINDOW:'.TABEL','DEFPROP')
LOCATE navnet in wp_name using @vm setting pos then
type=wp_typeif type=' thentype=wp_typepos=2if type=' thencall msg(@window,'Der er ikke knyttet nogen skrivelser til dette valg')return 0endenddot = wp_dotbookmkey= wp_bookmbtid = wp_btidend else
return 0end
* type = rowd
case_rowd =
open "","RPTLNK" to f.wp_fields else retv=repository("EXECUTE","OPENLAW*MSGERROR_NO_FILE") return 0 end retv = utility("CURSOR","H") Read rec from f.wp_fields, bookmkey else retv=repository("EXECUTE","OPENLAW*MSGERROR_NO_MERGES_FIELDS") return 0 end felter = rec form = rec bogmarker = rec retv = utility("CURSOR","H") locate form in children using @fm setting pos else retv=msg(@window,"Ingen form åben for tekstbehandling") retv=utility("CURSOR","A") return 0 end begin case case form=CHILD_CASE" * * it exists in object list * retv=set_property("CHILD_CASE","FOCUS",1) id=get_property("CHILD_CASE.CASE_ID_FIX","TEXT") if then id=cases@ setv=set_property("CHILD_CASE.CASE_ID_FIX","TEXT",id) retv=send_event("CHILD_CASE","READ") end gosub change_subj;* vælg den rigtige præsentation af personer case form =CHILD_KAL" id=get_property("CHILD_KAL.KAL_ID_FIX","TEXT") case form=CHILD_ADR" id=get_property("CHILD_ADR.ADD_ID_FIX","TEXT") case form=CHILD_CLIENT" id=get_property("CHILD_CLIENT.CLIENT_ID_FIX","TEXT") case form -1 retv=msg(@window,"Ukendt skærmbilled for overførsel til tekstbehandling") return 0 end case if then retv=repository("EXECUTE","OPENLAW*MSG**ERROR_NO_CHILD_CASE") return 0 end array = get_property(@window:'.TABEL_2','ARRAY') rowdata = get_property(@window:'.TABEL_2','ROWDATA') outputfilename = ARRAY ;* Nr.1 for ikke ta' overskrive de ekstisterende word filer. nr=1 Copy_File(dot, outputFileName,
,, Delete_flag) ;* collect .dot file for use. read wrec from f.setup, @username:'*':@station else wrec=' end wordstart=wrec if wordstart=0 then gosub openchannel end else wrec=1 write wrec to f.setup, @username:'*':@station else end end * retv = Set_Property ("CLIPBOARD", "TEXT", outputfilename) txt_msg = "Dot filen :":dot:" er nu kopieret til :":outputfilename:" Åben dokumentet i WordPro " retv = set_property('MDI.STATUSLINE','DEFPROP',txt_msg) if wp_service ne 'WINWORD' then RETV = msg(@window,txt_msg) end retv = utility("CURSOR","H") setv = set_property(FORM,"DDESERVICE", WP_SERVICE) if wp_service eq 'WINWORD' then setv = set_property(form,"DDECOMMAND", 'FileOpen("':outputfileName:'")') end else setv = set_property(form,"DDECOMMAND", 'Open("':outputfileName:'")');* commandoen duer ikke retv = Set_Property ("CLIPBOARD", "TEXT", outputfilename) ;* spm. er om den findes i wordpro eller hvad ? ;* end setv = set_property(FORM,"DDETOPIC", outputFileName) seterror = set_property(form,'DDEERROR') if seterror then gosub dde_er end setv=set_property(FORM,'DDELINK','HOT') max_fields = count(felter ,@vm) + (felter ne "") for x=1 to max_fields bogmark=bogmarker field =felter restfield=index(field,'.',1) rfield=trim(fieldrestfield+1,999) if bogmark ne "" then * * her er de enkelte bookmærker * * status=set_property(FORM,"DDEITEM",BOGMARK) ; txt=get_property(field,"TEXT") if rfield = "ADR_CLIENT_NAME" then navn=type:" ":txt status = set_property(FORM,"DDEDATA",txt) st = set_property('MDI.STATUSLINE','TEXT',txt) end if x=max_fields then * * create specialbogmærke for salæret afregningen * sal=.check_sal-]check if sal=1 then SAL_text = xlate('KAL' ,ID , 19 ,'X' ) SAL_BELOB = xlate('KAL' ,ID , 23 , 'X' ) SWAP @VM WITH CHAR(13):CHAR(10) IN SAL_TEXT SWAP @VM WITH CHAR(13):CHAR(10) IN SAL_BELOB retv=set_property(FORM ,'DDEITEM', 'SAL_TEXT' ) retv=set_property(FORM ,'DDEDATA', sal_text ) retv=set_property(FORM ,'DDEITEM', 'SAL_BELOB' ) retv=set_property(FORM ,'DDEDATA', sal_belob ) end end next x ;* next field * * update kal tabel * * if form=CHILD_CASE" then CHECK_OPDATER = .CHECK_OPDATER-]DEFPROP if CHECK_OPDATER=1 then s_add_kal (id,navn, init, type, btid, outputfilename, to); * opdate med info about word. end * * info to add on kal file * * RETV=SET_PROPERTY("CHILD_CASE.TABEL","ARRAY", tabel_arr) * RETV=SET_PROPERTY("CHILD_CASE.TABEL", "SORTEDCOL",1:@fm:2) * RETV=SET_PROPERTY("CHILD_CASE.TABEL","FOCUS", 1) end retv=utility("CURSOR","A") * * end program * * win = @window st = set_property('MDI.STATUSLINE','TEXT',
) ;* reset af statuslinieretv = send_event(win,'CLOSE')
RETURN 0
change_subj:
ARRAY = get_property('CHILD_CASE.INFO_KEY','ARRAY')nogler = arraytyper = array
Find uanset hvad først de bitors noglelocate 'KLIENT' in typer using @vm setting kpos thenklient_key=noglerklient_navn=xlate('ADR',klient_key,3,'X')end elsecall msg(@window,'Noget galt klient ikke oprettet')return 0endlocate 'MODPART' in typer using @vm setting dpos thendkey=noglermodpart_navn=xlate('ADR',dkey,3,'X')end elsedkey=nogler ;* da hentes klienten som nogle.modpart_navn='endlocate 'SAGSØGER' in typer using @vm setting spos thensgt_key=noglerend elsesgt_key=klient_keyendIF SGT_KEY=klient_key thenONEWAY=klient_navn :' - ':modpart_navnend elseONEWAY=modpart_navn:' - ':Klient_navnendretv=set_property('CHILD_CASE.PARTER','DEFPROP',ONEWAY)
return
openchannel:
setv = set_property(FORM,"DDESERVICE", WP_SERVICE)setv = set_property(form,"DDECOMMAND", 'FileOpen("':outputfileName:'")')setv = set_property(FORM,"DDETOPIC", outputFileName)seterror = set_property(form,'DDEERROR')if seterror thengosub dde_erRETV=set_property('MDI.STATUSLINE','DEFPROP', er )endBOGMARK=SAGSNR'TXT = ''setv=set_property(FORM,'DDELINK','HOT')status=set_property(FORM,"DDEITEM",BOGMARK)status=set_property(FORM,"DDEDATA",txt)return
dde_er:
if seterror =0x4001' then er=DMLERR_BUSY'if seterror =0x4002' then er=DMLERR_DATAACKTIMEOUT'if seterror =0x4003' then er=DMLERR_DLL_NOT_INITIALIZED'if seterror =0x4004' then er=DMLERR_DLL_USAGE'if seterror =0x4005' then er=DMLERR_EXECACKTIMEOUT'if seterror =0x4006' then er=DMLERR_INVALIDPARAMETER'if seterror =0x4007' then er=DMLERR_LOW_MEMORY'if seterror =0x4008' then er=DMLERR_MEMORY_ERROR'if seterror =0x4009' then er=DMLERR_NOTPROCESSED'if seterror =0x400a' then er=DMLERR_NO_CONV_ESTABLISHED'if seterror =0x400b' then er=DMLERR_POKEACKTIMEOUT'if seterror =0x400c' then er=DMLERR_POSTMSG_FAILED'if seterror =0x400d' then er=DMLERR_REENTRANCY'if seterror =0x400e' then er=DMLERR_SERVER_DIED'if seterror =0x400f' then er=DMLERR_SYS_ERROR'if seterror =0x4010' then er=DMLERR_UNADVACKTIMEOUT'if seterror =0x4011' then er=DMLERR_UNFOUND_QUEUE_ID'return
At 15 MAR 1999 06:54AM Oystein Reigem wrote:
Anders,
It was interesting to read what you do with DDE and Word. I have a museums customer who'd like his reports formatted in Word, and your posting made me think I could use DDE for that. I would be very grateful if you could give me a brief opinion on the following.
The background for my client's wish is that museums people are used to work with paper forms. With our customers each form contains information about an artefact, or a historical photo. The forms have fields for text and a space where you can paste in a photo. Most museums still have a large paper based catalogue. So I assume it's natural they want reports that emulate the old paper forms.
My app cannot offer the kind of report formatting my client wants. So he suggests I make a facility for exporting data to a text file, which he afterwards will print merge (? - "utskriftsfletting" - I don't know the proper English term since I have a Norwegian version of Word) into a Word template. He's already made the necessary templates.
Reading your posting makes me wonder if I could manage everything from within my app, and without too much development work on my side. E.g I could still export to a text file, and via DDE tell Word to do a print merge. Do you think that is difficult?
Or perhaps instead of exporting to a text file I could do what I think you do - insert data at bookmarks in a Word document. Afterwards I could tell Word to print it out. But my report contains many rows, which makes it slightly more complex. For each new row I would e.g have to (1) paste in a new chunk with fresh bookmarks, (2) insert all the data, and (3) disable all the bookmarks to get ready for the next row. So I assume the first alternative, with a merge process, is better.
Btw - do you think printing images will be a problem?
And where can I get an overview of which DDECOMMANDs I can use for Word? MSDN?
- Oystein -
At 15 MAR 1999 08:00AM Bob Watson wrote:
Another way you might do this is to develope a Word Project in VBA to manipulate the print merge. At the OI end you can export all required data to an ascii text file, start the project using DDE, and have the the project macros read the text file (or files - I export header, data and detail files) for all information required to do the merge - I found this to be precise way of manipulating Word templates.
Bob Watson