Using SetProfileString Statement to Set Values in WIN.INI File

ID: Q98835

The information in this article applies to:

SUMMARY

This article describes how to use the WordBasic SetProfileString statement in Word for Windows to add to or modify information in the Windows WIN.INI file. This article also describes a limitation of the SetProfileString statement in which you cannot store a line break character in the .Value argument.

Below are macros that demonstrate the use of the SetProfileString statement to set values in your WIN.INI file.

Word for Windows, Versions 6.0, 7.0, 7.0a

In the following macro, the proof path under the [MSAPPS] heading is changed to C:\WINDOWS\MSAPPS\PROOF.

 Sub MAIN
 SetProfileString "MSAPPS", "PROOF", "C:\WINDOWS\MSAPPS\PROOF"
 End Sub

In Windows 95 and Windows NT, settings are stored in the registry. You can still use SetProfileString and GetProfileString$() to set and return settings from a text file with the name WIN.INI, but neither the system nor Word uses these settings. To access and change values in the registry from within WordBasic, you need to use GetPrivateProfileString$() and SetPrivateProfileString.

Word for Windows, Versions 6.x

Word 6.0 for Windows stores most of the Word specific settings in the WINWORD6.INI file. This file is located in your \Windows directory. Using the SetPrivateProfileString statement, you can write to the WINWORD6.INI file.

 Sub MAIN
 SetPrivateProfileString "Microsoft Word", "INI-path", \
  "D:\WINWORD", "C:\WINDOWS\WINWORD6.INI"
 End Sub

If you are using Word 2.x for Windows, you can use the Microsoft Windows WritePrivateProfileString command in a WordBasic macro to write to 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 and windows and calls

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" 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.

SetProfileString Truncates at Line Break Character

You cannot store a line break character or any text that follows the line break in the .Value argument of the SetProfileString statement. If you assign a string to the .Value argument that contains two or more lines, separated by a line break character, SetProfileString stores only the portion of the string that precedes the first line break character.

Word for Windows, Versions 2.x

In the following macro, if a DOC-path statement is present in the [Microsoft Word 2.0] section of your WIN.INI file, the DOC-path will be changed to C:\WINWORD:

 Sub MAIN
 SetProfileString "Microsoft Word 2.0", "DOC-path", "C:\WINWORD"
 End Sub

Word for Windows, Version 1.x

The macro below sets the directory for the WINWORD.INI file to C:\WINWORD. If an INI-path statement is present in the [Microsoft Word] section of your WIN.INI file, the INI-path will be changed to C:\WINWORD.

 Sub MAIN
 SetProfileString "Microsoft Word", "INI-path", "C:\WINWORD"
 End Sub

MORE INFORMATION

Word 97

For information about how to do this in Word 97, while in the Visual Basic for Applications Editor click the Office Assistant, type "PrivateProfileString," (without the quotation marks), click Search, and then click to view "PrivateProfileString Property." To view examples, point to Example.

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120802
   TITLE     : Office: How to Add/Remove a Single Office
               Program or Component

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 284

Kbcategory: kbusage kbmacro KBSubcategory: Additional query words: getprofilestring chopped cut off word6 winword 7.0 word95 word7 winword2 1.0 1.10 1.10a 2.0 2.0a 2.0a-cd 2.0b 2.0c winword word8 word97 8.0

Version           : 1.x 2.x 6.0 6.0a 6.0c 7.0 7.
Platform          : WINDOWS

Last Reviewed: July 30, 1997