Sign up on the Revelation Software website to have access to the most current content, and to be able to ask questions and get answers from the Revelation community

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 then
	Read WordCtrlList from mdcHandle, WordCtrlId then
		wclCnt	= Count(WordCtrlList, @fm) + (WordCtrlList # '')
		Loop
			Data		= WordCtrlList
			MergeDoc	= Field(Data, '*', 2, 1)
			MergeData	= Field(Data, '*', 3, 2)
			Swap '*' with \0D0A\ in MergeData
			OSDelete MergeDataFile
			OSWrite MergeData to MergeDataFile
			Template	= DocLocation : MergeDoc : '.DOC'
			Gosub RunWord
			If not(Error) then
  • WordCtrlList = Delete(WordCtrlList, 1, 0 ,0)
			End else
				Msg('Failure writing Letter ' : MergeDoc : ' for ' : Field(Data, '*', 1, 1))
				Abort	= True$
			End
		Until WordCtrlList=' or Abort
		Repeat
	End
	Unlock mdcHandle, WordCtrlId else null
End

End

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 10
Until Error=0 or Error="
	Delay(1)
	void	= Set_Property(DDEWin,"DDECOMMAND",Command)
	Error  =Get_Property(DDEWin,"DDEERROR")
Next i

End

Command = ''

*debug

Return

View this thread on the forum...

  • third_party_content/community/commentary/forums_nonworks/773db36af5655e6f8525748d00476f84.txt
  • Last modified: 2023/12/28 07:39
  • by 127.0.0.1