Hi Tony,
Thank you for sending me the templates to review. The templates in question are in Word 97-2003 format and so they open in Compatibility Mode (on my machine). You may wish to convert these, especially if you are using Office 365. You can do so by clicking on File, Info and then beside Compatibility Mode you should see Convert. Click on this and then you will be prompted with the ability to choose OK or Cancel...read the information prior to choosing. If you click OK then it will convert the document to the most recent version of MS Word (on that client machine). Creating backups of the templates prior to doing so is advisable.
You will need to test it to make sure you don't lose any functionality (in particular the macros) by doing the conversion but I'm thinking it should be fine.
I too received the same error trying to open these templates until I converted them from Word 97-2003 (or use the other approach below). This of course assumes that the client machines this will be accessed on have a higher version of MS Word than 97-2003 (I guess in this case Office 365).
The other approach, if you don't want to convert the templates to the latest MS Word version, is you'll need to change the Document Trust settings in MS Word. MS Word is thinking that you received this file over the internet and so is preventing you from accessing it (via COM) while this checkmark is in place. This may be a false positive as this also happens sometimes when dealing with documents that were created in versions of Office that are no longer supported. Go to File, Options and Trust Center then click on Trust Center Settings. Once there click on Protected View. Remove the first check mark as seen in the picture:
This may be something that you are not permitted to do by your IT admin, whether due to internal policies or GPO settings and, admittedly, doing so does come with some risk. This means you may have to do the file conversion as above which would be my recommendation anyway.
HTH...regards,
Mark
Thanks for replying. I actually did not hard code the file name. I have a variable name for the file name.
The actual scripts are like this.
string ls_doc_name = '';
ls_doc_name = is_dir + is_file_name // instance variables to hold directory and file name
if FileExists(ls_doc_name) then
return -1
end if
ob = create nvuo_oletrap
result = ob.ConnectToNewObject("word.application")
if result <> 0 then
destroy ob
return -1
end if
result = ob.Documents.Add(ls_doc_name)
I am not sure why it crashed. I also tried Open() and it did not work either.
Thanks again.
Tony
No it probably wouldn't make a difference with .Open(). By the way, when you use .Open() with a template it will open the actual template versus opening a new document based off of the template so you probably don't want that anyway.
However, are the following lines of code correct:
if FileExists(ls_doc_name) then
return -1
end if
It appears to be saying if it finds the file return a -1, so the opposite would mean if it can't find the file it will continue and try to connect to the file which would bring about the error...have I got that right?
As well...
1) What version of office are you using?
2) What OS are you using?
3) Can you provide more details on nvuo_oletrap?
Unfortunately I don't presently have PB 2017R3 on any of my computers at the moment so I can't test with the same PB version but I don't recall there being the issue you're experiencing.