1. Toan Nguyen
  2. PowerBuilder
  3. Friday, 14 May 2021 19:17 PM UTC

Hi Everyone,

In my PB application (PB2017 R3), I created an OLEObject variable and connect to MS Word's OLE interface (word.application). I want to allow user to enter information in the .dotx template in MS Word. The template has no edit restrictions.

Below is a snippet of my codes:

ob = create nvuo_oletrap

result = ob.ConnectToNewObject("word.application")

if result <> 0 then
destroy ob
return -1
end if

result = ob.Documents.Add("form.dotx")

....

My application crashed when trying to call the Add().

The system returns error number 35 with the error message: "Error calling external object function 'add' at line 56..."

Does anyone have any idea or encountered this issue?

Thanks in advance for everyone's help!

Tony

 

 

 

Mark Goldsmith Accepted Answer Pending Moderation
  1. Wednesday, 19 May 2021 19:46 PM UTC
  2. PowerBuilder
  3. # 1

You're welcome Tony and glad to hear that Enable Editing and removing the Protected View status resolved the issue for you. 

As for Office 365 supporting DOT templates, my understanding is that it does.  I don't have access to Office 365 on the computer I'm working with at the moment but do have it on another computer.  It may not be until this evening or some time tomorrow but when I get a chance I will test it on that machine.

Regards,

Mark

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Monday, 17 May 2021 05:50 AM UTC
  2. PowerBuilder
  3. # 2

Have you tried to catch the OLERuntimeError exception? See in the "description" property of the exception. There you could find a word error message about the reason of fail.

Comment
  1. Mark Goldsmith
  2. Monday, 17 May 2021 17:01 PM UTC
Hi René,

Thanks for the suggestion and I too had looked at the error content early on but unfortunately it only says that "A file error has occurred" and so the potential cause of the file error is the challenge.

I've paused the application, clicked Enable Editing in MS Word, then continued the application and I was able to assign values to any of the bookmarks.

I still think it's related to the file being opened in Protected View (due to machine/ GPO policies or something similar) and once Tony gets past that hopefully the error will be gone.
  1. Helpful
  1. Toan Nguyen
  2. Wednesday, 19 May 2021 12:28 PM UTC
Hi Mark and Rene,



Thank you both for helping with this issue.



Mark - you were right about protected view on the file set by my organization for security purpose. Now the application can open the file for the converted .dotx template once the file was given "Unrestricted Access".



So, back to the issue. Originally, we had the .dot template (Word 97 - 2003) in our application and it was working fine. It seems that once we upgraded to MS Word 365, we have the issue with the template. The bookmarks on the .dot template were not getting populated correctly or blanks. Now that I am using the converted .dotx template, everything works great.



I thought that Office 365 still supports .dot template because I can open it in MS Word. Do you know why it is an issue when we use .dot in the application?



Once again, thank you both for helping me with the issue.



Regards,



Tony
  1. Helpful
There are no comments made yet.
Toan Nguyen Accepted Answer Pending Moderation
  1. Saturday, 15 May 2021 18:46 PM UTC
  2. PowerBuilder
  3. # 3

Hi Mark,

Thank you very much for taking your time to look into this issue for me.

Unfortunately, my organization set all the checkboxes in the protected view section for security purpose. So, I can't do much with the settings.

However, I followed your suggestion and converted the .dot (97 - 2003) template to the .dotx.

I encountered the .Add error when ran against the new .dotx template. You mentioned that you were able to open the .dotx template once you converted .dot to .dotx.

Can you do me a favor and let me know if you are able to open the .dotx template in the attached zip file in this reply?

I also included the error message I got when running against the new template.

Once again, thank you very much for trying to help me.

Regards,

Tony

 

Attachments (1)
Comment
  1. Mark Goldsmith
  2. Monday, 17 May 2021 01:02 AM UTC
Hi Tony,

I tried the template you sent and since it was a file I received over the internet, and I have the checkmark set to only open a file originating from the internet in protected mode, of course I was not able to access the file while doing my test. How are you receiving the file? Is it being sent to you or are you the creator of the file?

What I did next was open the template from within File Explorer and enabled editing of the file, then saved it under a different name and was then able to create a new document based off of that template from within PowerBuilder.

If you place the following statement...ob.Application.Visible = True...after the ConnectToNewObject() statement are you able to see MS Word and the file in question (you'll still receive the error message but this will allow you to see the state of MS Word once the file is actually opened)?

If so MS Word has likely opened the document in Protected View with an Enable Editing button you can click (which is what I did in the second paragraph above). Does the same thing happen if you simply double-click on the file from within File Explorer? Does it open in the same state as it did from within PowerBuilder? If so then it's not likely PowerBuilder that is causing the issue and there is still something in your setup/ environment that is preventing the document from being opened normally. It's hard to say what that might be but could be anything from your GPO policies, maybe security settings preventing the normal opening of the file due to macros being part of the document etc. You may need to engage your IT support for assistance in that regard.

The above may not be much more help to you but based on your answers to my questions and trying what I did hopefully that will add some insight.
  1. Helpful
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Saturday, 15 May 2021 15:25 PM UTC
  2. PowerBuilder
  3. # 4

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

Comment
There are no comments made yet.
Toan Nguyen Accepted Answer Pending Moderation
  1. Saturday, 15 May 2021 03:52 AM UTC
  2. PowerBuilder
  3. # 5

Hi Mark,

Thanks for responding to my issue.

I copied the script wrong in here. The actual script: if NOT FileExists(ls_doc_name).return -1 end if

1) Version of Office: MS Word 365,
2) Windows 10,
3) nvuo_oletrap is inherited from the standard class OLEOBJECT user object.

I suspect it could be the template. So, if you don't mind, I am attaching a templates zip file to this reply for you to see if you can open them in the later version of PowerBuilder you have. They are .dot (Word 97-2003) and .dotx templates. The .dotx template is the converted version from the .dot template.

I appreciate your help very much.

Thanks again.

Tony

Attachments (1)
Comment
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Friday, 14 May 2021 19:43 PM UTC
  2. PowerBuilder
  3. # 6

Hi Tony,

I suspect it can't find the file you've identified and so as a test you may wish to include the full path and see if that works.

While you may not want this to be ultimately how your app works, as another test use GetFileOpenName() to explicitly pick out the file and see if it still fails.

HTH...regards,

Mark

Comment
  1. Toan Nguyen
  2. Friday, 14 May 2021 22:14 PM UTC
Hi 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

  1. Helpful
  1. Mark Goldsmith
  2. Friday, 14 May 2021 23:48 PM UTC
Hi 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.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.