opening word from dxl

I am trying to open a .docx file from dxl and am having a little trouble. I hacked this code together - I have no idea what I am doing here so this is probably going to be some of the worst code you will ever see - and it is not quite working. When I call the function, MS Word opens up fine but the specific .docx file doesn't open. Any thoughts?
 

void openWordDoc(string docName){
    // declarations
        OleAutoObj objWord = oleCreateAutoObject("Word.Application")
        olePut(objWord, "Visible", true)
        OleAutoObj objDoc = null
        oleGet(objWord, "Documents", objDoc)
        OleAutoArgs args = create()
        
        // open file
        put(args, docName)
        oleMethod(objDoc, "Open", args)
        clear args
 
        // clean up
        put(args, 1)
        oleMethod(objWord, "Close", args)
        oleMethod(objDoc, "Close", args)
        delete(args)
        oleCloseAutoObject objWord
        oleCloseAutoObject objDoc
}

SystemAdmin - Wed Jul 27 16:44:31 EDT 2011

Re: opening word from dxl
SystemAdmin - Wed Jul 27 17:27:57 EDT 2011

I found the problem. In the file path I was using "/" rather than "\\". I changed it to "\\" and it works fine, but when I use similar code to open an excel sheet and run a macro it works fine with "/"...any ideas why it matters for word and not excel?

Re: opening word from dxl
llandale - Wed Jul 27 18:28:35 EDT 2011

I don't think the following is better but if your file already exists then you can do this:

string NameFile = "c:/MyFolder\\MyOtherFolder\\MyWordDoc.docx"
string NameWord = "C:\\Program Files\\Microsoft Office\\Office12\\WinWord.exe"
system(NameWord " " NameFile)

This is much like using the command prompt. It opens the file with word but there is no communication channel. Hassle when you install a new version of Word.

For text files its easy, since "notepad.exe" is in the default path:
system("NotePad.exe " NameFile)

  • Louie

This may be better:
string NameWord = getRegistry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Common\\InstallRoot", "Path")

What I WAS doing is searching all over the place until I found WinWord.exe
if (null NameWord) getRegistry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\11.0\\Common\\InstallRoot", "Path")

Re: opening word from dxl
Reik_Schroeder - Thu Jul 28 04:12:52 EDT 2011

Hi Adam,

the simplest way to open the document is to use the

activateURL

function. It will let windows determine the assigned application ;-)

Best regards from Berlin
Reik

_______________________Evosoft GmbH / Siemens AG

Re: opening word from dxl
SystemAdmin - Thu Jul 28 10:54:05 EDT 2011

Reik_Schroeder - Thu Jul 28 04:12:52 EDT 2011
Hi Adam,

the simplest way to open the document is to use the

activateURL

function. It will let windows determine the assigned application ;-)

Best regards from Berlin
Reik

_______________________Evosoft GmbH / Siemens AG

Thanks for your help gentlemen.
-Adam