FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to read settings in Word
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
How to read settings in Word
Posted: Thu May 04, 2023 02:52 PM

Hello,

How can I read a setting of Word in my FWH application?

I need to know the startup-folder of Word?

And if someone knows how, also the startup-folder of Excel or Outlook.

Thank you very much for any help.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to read settings in Word
Posted: Thu May 04, 2023 03:15 PM
Dear Michel,

from chatGPT 4:
Code (fw): Select all Collapse
LOCAL oWord, cStartupPath
oWord = CREATEOBJECT("Word.Application")
cStartupPath = oWord.Options.DefaultFilePath(10) && 10 is wdStartupPath
? "Word Startup Folder:", cStartupPath
oWord.Quit
what specific setting are you looking for ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: How to read settings in Word
Posted: Thu May 04, 2023 03:50 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: How to read settings in Word
Posted: Fri May 05, 2023 04:20 AM
hi,
driessen wrote:I need to know the startup-folder of Word?
And if someone knows how, also the startup-folder of Excel or Outlook.
do you mean which "Start" Folder when User want to "open" a Document or Sheet ?

as it is a Microsoft Product it will use Windows default Folder "Personal Files\Document"
... but File-Dialog Control "might" show you "last Folder"

---

under Xbase++ i have use a "Trick" to show "right" Folder

before call ActiveX i call File-Dialog Control "invisible" to set new Path and than close it
to use a "invisible" Control "just" set Position "outside" Screen e.g. {-1000, -1000}
greeting,

Jimmy
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: How to read settings in Word
Posted: Fri May 05, 2023 08:58 AM

Thanks a lot for any help.

I have the information I needed.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: How to read settings in Word
Posted: Mon Jul 31, 2023 02:17 PM

Hello,

I know now how to read settings in Word.

But can anyone help me in changing the settings in Word?

I also need to know how to put the startup setting in Word back to its default value?

Thank you.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to read settings in Word
Posted: Mon Jul 31, 2023 02:54 PM

Dear Michel,

How are you finally reading the settings ?

Please post the code to see how to save them, thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: How to read settings in Word
Posted: Mon Jul 31, 2023 03:30 PM
Antonio,

This is the code with the method how I read the startup folder of Word :
Code (fw): Select all Collapse
******************************************************************************

LOCAL cStartupPath := ""

PRIVATE cWord

WordOle()

cStartupPath := cWord:Options:DefaultFilePath(8) // 8 is wdStartupPath

* CStartupPath contains the startup folder of Word.
* Standard it is : %USERPROFILE%\AppData\Roaming\Microsoft\Word\STARTUP
*                       but it might be changed for external reasons.

******************************************************************************

PROCEDURE WordOle

*  This procedure builds the OLE-connection with Word

   IF (cWord := WinWordObj()) = NIL
      MsgAlert("Microsoft Word wasn't installed on this computer","Alert")
   ENDIF

RETURN

******************************************************************************
I want to change the startup folder of Word from my FWH-application.

Thanks.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to read settings in Word
Posted: Tue Aug 01, 2023 05:49 AM

Dear Michel,

Please try this:

cWord:Options:DefaultFilePath(8) = cNewPath

MsgInfo( cWord:Options:DefaultFilePath(8) )

and check if it works and changes the path or generates an error

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: How to read settings in Word
Posted: Tue Aug 01, 2023 12:12 PM

Antonio,

While compiling your example, I get the error : Error E0022 Invalid lvalue ':'

So the settings in Word can't be changed that way.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to read settings in Word
Posted: Tue Aug 01, 2023 05:51 PM

Dear Michel,

Please try it this way:

cWord:Options:DefaultFilePath[8] = cNewPath

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to read settings in Word
Posted: Tue Aug 01, 2023 05:53 PM
Dear Michel,

Please review this:
https://learn.microsoft.com/en-us/office/vba/api/word.options.defaultfilepath
https://documentation.help/VBAWD10/woproDefaultFilePath.htm

It should work as the first try but Harbour syntax does not allows it
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: How to read settings in Word
Posted: Tue Aug 08, 2023 11:06 PM

Antonio,

I'm sorry, I wasn't able to solve my last problem yet, but I have a new question.

I need to read in my Fwh-application the exact position where my cursor is in a Word-document.

Later on I have to put the cursor back in its original position.

How can I do this?

Thx.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to read settings in Word
Posted: Wed Aug 09, 2023 07:27 AM

Dear Michel,

To save the current current position:

nStartPosition = oWordApp:Selection:Range:Start

nEndPosition = oWordApp:Selection:Range:End

To later restore the cursor position:

oWordApp:Selection:SetRange( nStartPosition, nEndPosition )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: How to read settings in Word
Posted: Thu Aug 10, 2023 12:56 PM

Antonio,

Once again, thank you very much.

It's working fine.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Continue the discussion