Opening 2 Word-documents from my application - solved

Post Reply
User avatar
driessen
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Opening 2 Word-documents from my application - solved

Post by driessen »

Hello,

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

This is the source code I use:

Code: Select all | Expand

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.
Last edited by driessen on Sat Apr 22, 2023 10:55 am, edited 1 time in total.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.09 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
Antonio Linares
Site Admin
Posts: 42512
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Opening 2 Word-documents from my application

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
driessen
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

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

Post by driessen »

Hello Antonio,

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

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.09 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

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

Post 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

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

oWord  := WinWordObj()
oDoc1 := oWord:Documents:Open( cFile1 )
oDoc2 := oWord:Documents:Open( cFile2 ) 
 
Even if you call WinWordObj() again and again nothing happens
Regards

G. N. Rao.
Hyderabad, India
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

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

Post 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
greeting,
Jimmy
User avatar
driessen
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

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

Post 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.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.09 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

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

Post 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

Function OutlookObj(); return FWGetOleObject( "Outlook.Application",   @lOutlook  )
greeting,
Jimmy
User avatar
driessen
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

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

Post by driessen »

Thanks a lot for your help.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.09 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Post Reply