DDE for a DDE dummy - and Word 2003 (OpenInsight 32-bit Specific)
At 21 JUL 2008 09:00:16AM Simon G Wilmot wrote:
Hi All,
Can a DDE beginner please have some help.
I have managed to cobble together some code from a variety of sources that starts to work, however I have two (or more) problems.
a) When I start up word I get the SQL select message, is there a way of suppressing this.
b) Once the document has been opened, the data fields swap in correctly, but I want it to go straight to print and then close down word.
I enclose the following code for review please !!
I think part of the problem, apart from my lack of knowledge on this, is that a lot of the DDE code is from an older version of word.
Regards,
Simon
Compile Subroutine MD_Generate_Letters(Param)
$Insert Logical
Declare Function Get_Property, Set_Property, Start_Window, Utility
Declare Subroutine Delay, End_Window, Msg
Abort = False$
MergeDataFile = 'H:\MERGEDAT.DOC'
NumberOfCopies = 1
Suppression = False$
Collated = False$
DDEWin = 'MD_DDE'
WordExe = 'C:\Program Files\Microsoft Office\Office11\winword.exe'
DocLocation = 'H:\'
Open 'MD_CONTROL' to mdcHandle then
WordCtrlId = 'WORD_LETTERS'Lock mdcHandle, WordCtrlId thenRead WordCtrlList from mdcHandle, WordCtrlId thenwclCnt = Count(WordCtrlList, @fm) + (WordCtrlList # '')LoopData = WordCtrlListMergeDoc = Field(Data, '*', 2, 1)MergeData = Field(Data, '*', 3, 2)Swap '*' with \0D0A\ in MergeDataOSDelete MergeDataFileOSWrite MergeData to MergeDataFileTemplate = DocLocation : MergeDoc : '.DOC'Gosub RunWordIf not(Error) then
WordCtrlList = Delete(WordCtrlList, 1, 0 ,0)End elseMsg('Failure writing Letter ' : MergeDoc : ' for ' : Field(Data, '*', 1, 1))Abort = True$EndUntil WordCtrlList=' or AbortRepeatEndUnlock mdcHandle, WordCtrlId else nullEndEnd
Return
*——+
RunWord:
*——+
void = Start_Window(DDEWin, @Window,
,
,) void = Set_Property(DDEWin ,'DDSERVICE', 'WINWORD' ) void = Set_Property(DDEWin ,'DDETOPIC', Template ) void = Set_Property(DDEWin ,'DDELINK', 'AUTO' ) void = Utility('RUNWIN', WordExe : ' ' : Template, 1) Command =
Command := 'FileOpen .Name= : Quote(Template) :
Gosub ExecuteCommand Command := 'MailMergeReset' Gosub ExecuteCommand Command := 'MailMergeOpenDataSource .Name= : Quote(MergeDataFile) Command := ', .ConfirmConversions=0, .Revert=1' Gosub ExecuteCommand *Command := 'SendKeys "{enter}",-1' *Gosub ExecuteCommand *Command := 'MailMerge .Destination=1, .MergeRecords=0, .Suppression= : Suppression : ', .MailMerge' *Gosub ExecuteCommand Command := 'MailMerge .Destination=0, .MergeRecords=0, .Suppression= : Suppression : ', .MailMerge' Gosub ExecuteCommand Command := 'FilePrint .Background=0, .AppendPrFile=0, .Range=0, .Type=0,' Command := ' .NumCopies= : NumberOfCopies : ', .PrintToFile=0, .Collate= : Collated :
Gosub ExecuteCommand
Command := 'FileClose 2'
Gosub ExecuteCommand
Command := 'FileCloseAll 2'
Gosub ExecuteCommand
Command := 'Kill ' : Quote(MergeDataFile) :
Gosub ExecuteCommand Command := 'FileExit 2' Gosub ExecuteCommand End_Window(DDEWin) Return *————-+ ExecuteCommand: *————-+ Delay(1) Error =
void = Set_Property(DDEWin,"DDECOMMAND",Command)
Error =Get_Property(DDEWin,"DDEERROR")
If Error then
For i=1 to 10Until Error=0 or Error="Delay(1)void = Set_Property(DDEWin,"DDECOMMAND",Command)Error =Get_Property(DDEWin,"DDEERROR")Next iEnd
Command = ''
*debug
Return