PrivateProfileString Property

Applies To

System object.

Description

Returns or sets a string in a settings file or the Windows registry. Read/write String.

Syntax

expression.PrivateProfileString(Filename, Section, Key)

expression Required. An expression that returns a System object.

Filename Required String. The file name for the settings file. If there's no path specified, the Windows folder (Windows) or the Preferences folder (Macintosh) is assumed. If you're using Windows 95 or Windows NT to return a setting from the registry, Filename must be an empty string ("").

Section Required String. The name of the section in the settings file that contains Key. In a Windows settings file, the section name appears between brackets before the associated keys (don't include the brackets with Section). If you're returning a setting from the Windows registry, Section should be the complete path to the key, including the root (for example, "HKEY_CURRENT_USER\Software\Microsoft
\Office\8.0\Word\Options").

Key Required String. The key whose setting you want to retrieve. In a Windows settings file, the key name is followed by an equal sign (=) and the setting. If you're returning a setting from the Windows registry, Key should be the value in the key specified by Section (for example, "Tools-Path").

Remarks

You can write macros that use a settings file to store and retrieve settings. For example, you can store the name of the active document when you quit Word so that it can be reopened automatically the next time you start Word. In Windows, a settings file is a text file with information arranged like the information in the Windows 3.x Win.ini file. On the Macintosh, a settings file is a resource file such as Word Settings (97).

See Also

ProfileString property.

Example

This example sets the current document name as the LastFile setting under the MacroSettings heading in Settings.txt.

System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
    "LastFile") = ActiveDocument.FullName
This example returns the LastFile setting from Settings.txt and then opens the document stored in LastFile.

LastFile = System.PrivateProfileString("C:\Settings.Txt", _
    "MacroSettings", "LastFile")
If LastFile <> "" Then Documents.Open FileName:=LastFile
This example displays the default user name setting from the Windows registry.

aName = System.PrivateProfileString("", _
    "HKEY_CURRENT_USER\Software\Microsoft\MS Setup (ACME)\User Info", _
    "DefName")
MsgBox aName