Hi all, I have problems with automation and new version of Office. With version 2010 it is all ok! I'll try to replace a string in a .doc document, but it seems to me word 2016 did not respond to automation. I can open the file but when I close automation in task-manager i see winword.exe running... It is possible that there is a security mechanism so automation in blocked? Anyone had this problems?
My code is like this:
// check whether Word is found and retrieve its version nVersion is int nVersion = nVersionOffice("Word") IF nVersion = 0 THEN Error("Word non è installato su questo computer, non puoi usare questa funzione") RETURN END IF nVersion < 8 THEN Error("Per usare questa funzione devi avere installato Word 97 o successivo") RETURN END
sNomeFile, sNomeFileTmp is string sNomeFile=CompleteDir(ExeInfo(exeDirectory))+"myfile.doc" sNomeFileTmp="c:\temp\myfile.doc"
IF fFileExist(sNomeFile) THEN fCopyFile(sNomeFile,sNomeFileTmp) END
IF NOT fFileExist(sNomeFileTmp) THEN Error("File myfile.doc non presente") RETURN END
ChiudiWord()
pautMyWord=new object Automation "Word.application"
pautMyWord>>documents>>Open(sNomeFileTmp, True, True) //pautMyWord>>Visible=False
WHEN EXCEPTION IN pautMyWord>>Selection DO Error("MyWordSelection") GOTO FINE END
// 1: WdFindContinue // 2: WdReplaceAll WHEN EXCEPTION IN pautMyWord>>Selection>>Find>>Execute("$DataLettera$",False,True,False,False,False,True,1,False,NoSpace(EDT_Data_Lettera),2) DO Error("MyWordSelectionFindExecute_DataLettera", ErrorInfo(errFullDetails)) GOTO FINE END WHEN EXCEPTION IN pautMyWord>>Selection>>Find>>Execute("$DataAggIta$",False,True,False,False,False,True,1,False,NoSpace(EDT_Data_Aggiornamento_ita),2) DO Error("MyWordSelectionFindExecute_DataAggIta", ErrorInfo(errFullDetails)) GOTO FINE END WHEN EXCEPTION IN pautMyWord>>Selection>>Find>>Execute("$DataAggEng$",False,True,False,False,False,True,1,False,NoSpace(EDT_Data_Aggiornamento_eng),2) DO Error("MyWordSelectionFindExecute_DataAggEng", ErrorInfo(errFullDetails)) GOTO FINE END
pautMyWord>>Visible=True
FINE:
Then in the close procedure of the window:
WHEN EXCEPTION IN pautMyWord>>documents>>Close(0) pautMyWord>>Application>>Quit delete pautMyWord DO END
but winword.exe is still executing after close.
Tnx
Andrea |