Page 1 of 1

Opening 2 Word-documents from my application - solved

PostPosted: Sat Apr 22, 2023 8:27 am
by driessen
Hello,

I want to open 2 Word-documents in my application.

This is the source code I use:
Code: Select all  Expand view
oWord1 := TOleAuto():New("Word.application")
oDoc1 := oWord1:Documents:Open(cFile1)

oWord2 := TOleAuto():New("Word.application")
oDoc2 := oWord2:Documents:Open(cFile2)
When the line starting with oWord2 is executed, this message always appears:

Image

Does anyone know why this message appears?
Is there a solution to avoid this message?

Thank you very much in advance for any help.

Re: Opening 2 Word-documents from my application

PostPosted: Sat Apr 22, 2023 10:05 am
by Antonio Linares
Dear Michel,

I have asked chatgpt about it:
Open the relevant Microsoft Office application (e.g., Word, Excel).
Click "File" in the top-left corner.
Click "Options" to open the Options dialog box.
Select "Trust Center" from the left-hand menu, then click the "Trust Center Settings" button.
In the Trust Center dialog, click "Macro Settings" in the left-hand menu.
Select "Disable all macros with notification" (if not already selected). This setting will allow you to enable macros on a per-document basis with the "Enable Content" button.
Click "OK" to close the Trust Center dialog, then click "OK" again to close the Options dialog.
Close and reopen the document. You should now see the yellow bar with the "Enable Content" button. Click it to enable macros for this specific document.


Open the relevant Microsoft Office application (e.g., Word, Excel).
Click "File" in the top-left corner.
Click "Options" to open the Options dialog box.
Select "Trust Center" from the left-hand menu, then click the "Trust Center Settings" button.
In the Trust Center dialog, click "Trusted Locations" in the left-hand menu.
Click the "Add new location" button.
Browse to the folder where the document is located, select it, and click "OK."
Make sure the "Subfolders of this location are also trusted" option is checked if you want to trust all subfolders.
Click "OK" to close the Trust Center dialog, then click "OK" again to close the Options dialog.
Close and reopen the document. Macros should now be enabled for documents from the trusted location.

Re: Opening 2 Word-documents from my application - solved

PostPosted: Sat Apr 22, 2023 10:56 am
by driessen
Hello Antonio,

Was it as simple as that?
Thank you very much for your help.
Have nice weekend.

Re: Opening 2 Word-documents from my application - solved

PostPosted: Sun Apr 23, 2023 12:19 pm
by nageswaragunupudi
driessen wrote:Hello,

I want to open 2 Word-documents in my application.

This is the source code I use:
Code: Select all  Expand view
oWord1 := TOleAuto():New("Word.application")
oDoc1 := oWord1:Documents:Open(cFile1)

oWord2 := TOleAuto():New("Word.application")
oDoc2 := oWord2:Documents:Open(cFile2)
When the line starting with oWord2 is executed, this message always appears:

Image

Does anyone know why this message appears?
Is there a solution to avoid this message?
Thank you very much in advance for any help.


Please use FWH WinWordObj() function
Code: Select all  Expand view
oWord  := WinWordObj()
oDoc1 := oWord:Documents:Open( cFile1 )
oDoc2 := oWord:Documents:Open( cFile2 )
 


Even if you call WinWordObj() again and again nothing happens

Re: Opening 2 Word-documents from my application - solved

PostPosted: Sun Apr 23, 2023 1:27 pm
by Jimmy
hi,

Word or Excel are MDI Apps so you can open a 2nd Document / Sheet in new Child Window and don´t need a new Instance

Re: Opening 2 Word-documents from my application - solved

PostPosted: Sun Apr 23, 2023 2:37 pm
by driessen
Guys,

Thank you so much to you both for your help.

WinWordObj() and ExcelObj() are 2 function I didn't know they exist.
Is there also such a function for Outlook?
OutlookObj() isn't working.

Thanks again.

Re: Opening 2 Word-documents from my application - solved

PostPosted: Sun Apr 23, 2023 3:20 pm
by Jimmy
hi,

WinWordObj() and ExcelObj() are in c:\fwh\source\function\olefuncs.prg
but they both pint to FWGetOleObject ( in same PRG )

so you can write
Code: Select all  Expand view
Function OutlookObj(); return FWGetOleObject( "Outlook.Application",   @lOutlook  )

Re: Opening 2 Word-documents from my application - solved

PostPosted: Sun Apr 23, 2023 3:51 pm
by driessen
Thanks a lot for your help.