Microsoft KB Archive/86470

{|
 * width="100%"|

How to Use WordBasic to Return Values from Win.ini or Registry

 * }

Q86470

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows, version 7.0
 * Microsoft Word for Windows NT, version 6.0

-

SUMMARY
Using the Microsoft WordBasic GetProfileString and GetPrivateProfileString functions, you can extract information from the Windows Win.ini file if you are using Windows 3.x or the Registry if you are using Word 7.0.

Below are macros that demonstrate the use of the GetProfileString and GetPrivateProfileString functions.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code &quot;as is&quot; without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Word 7.0 for Windows 95 and Word for Windows NT
In Windows 95 and Windows NT, settings are stored in the Registry. You can use SetProfileString and GetProfileString$ to set and return settings from a text file with the name Win.ini (see Word version 6.x macro below), but neither Windows 95, Windows NT, nor Word 7.0 uses these settings. To access values in the Registry from within WordBasic, you need to use the GetPrivateProfileString$ function.

In the following macro, the program directory path for Word 7.0 in the Windows registry is retrieved and stored in the proofdir$ variable. Note: For Word for Windows NT, substitute 6.0 for 7.0 in the registry key for GetPrivateProfileString$ shown below.

Sub MAIN progdir$ = GetPrivateProfileString$(&quot;HKEY_CURRENT_USER\Software\Microsoft\Word\7.0\options&quot;, &quot;Programdir&quot;, &quot;&quot;) MsgBox progdir$ End Sub

Word 6.x for Windows
In the following macro, the proof path under the [MSAPPS] heading in the Win.ini file is retrieved and stored in the A$ variable.

 Sub MAIN A$ = GetProfileString$(&quot;MSAPPS&quot;, &quot;PROOF&quot;) Msgbox &quot;Proof directory is &quot; + A$ End Sub

Word 2.x for Windows
If the DOC-path statement is not present in the [Microsoft Word 2.0] section of your Win.ini file, a dialog box indicates that the default directory has not been set.

 Sub MAIN A$ = GetProfileString$(&quot;Microsoft Word 2.0&quot;, &quot;DOC-Path&quot;) If A$ = &quot;&quot; Then MsgBox &quot;Default Directory is not set&quot; Else MsgBox &quot;Default Directory is &quot; + A$ End If End Sub

Word 1.x for Windows
 Sub MAIN A$ = GetProfileString$(&quot;Microsoft Word&quot;, &quot;DOC-Path&quot;) If A$ = &quot;&quot; Then MsgBox &quot;Template Directory is not set&quot; Else MsgBox &quot;Template Directory is &quot; + A$ End If End Sub

MORE INFORMATION
If you are using Word 7.0 and the GetPrivateProfileString$ function in Windows 95 and Windows NT to return a setting in the Registry, you must specify the complete path to the key, including the root (for example, &quot;HKEY_CURRENT_USER\software\Microsoft\Word\7.0\Options&quot;).

Word 6.0 for Windows stores most of the Word-specific settings in the Winword6.ini file. This file is located in your Windows folder. Using the GetPrivateProfileString statement, you can read information from the Winword6.ini file.

If you are using Word 2.x for Windows, you can use the Microsoft Windows GetPrivateProfileString command in a WordBasic macro to read information from an .ini file other than the Win.ini file. For more information, query on the following words in the Microsoft Knowledge Base:

"private and text and file"