개인 프로필 문자열은 나중에 사용하기 위해 응용 프로그램 / 문서 외부에 사용자 특정 정보를 저장하는 데 자주 사용됩니다.

예를 들어 대화 상자 / 사용자 양식의 최신 콘텐츠에 대한 정보, 통합 문서를 연 횟수 또는 송장 템플릿에 대해 마지막으로 사용한 송장 번호를 저장할 수 있습니다.

각 사용자의 개인 프로필 문자열은 레지스트리에 저장할 수 있습니다. 로컬 하드 디스크 나 공유 네트워크 폴더에서 INI 파일을 사용할 수도 있습니다.

다음은 레지스트리의 개인 프로필 문자열에 쓰고 읽기위한 매크로 예제입니다.

' the examples below assumes that the range B3:B5 in the active sheet contains

' information about Lastname, Firstname and Birthdate

Sub WriteUserInfoToRegistry()

' saves information in the Registry to

' HKEY_CURRENT_USER\Software\VB and VBA Program Settings\TESTAPPLICATION

On Error Resume Next

SaveSetting "TESTAPPLICATION", "Personal", "Lastname", Range("B3").Value

SaveSetting "TESTAPPLICATION", "Personal", "Firstname", Range("B4").Value

SaveSetting "TESTAPPLICATION", "Personal", "Birthdate", Range("B5").Value

On Error GoTo 0

End Sub

Sub ReadUserInfoFromRegistry()

' reads information in the Registry from

' HKEY_CURRENT_USER\Software\VB and VBA Program Settings\TESTAPPLICATION

Range("B3").Formula = GetSetting("TESTAPPLICATION", "Personal", "Lastname", "")

Range("B4").Formula = GetSetting("TESTAPPLICATION", "Personal", "Firstname", "")

Range("B5").Formula = GetSetting("TESTAPPLICATION", "Personal", "Birthdate", "")

End Sub

' the example below assumes that the range D4 in the active sheet contains

' information about the unique number

Sub GetNewUniqueNumberFromRegistry()

Dim UniqueNumber As Long

UniqueNumber = 0

On Error Resume Next

UniqueNumber = CLng(GetSetting("TESTAPPLICATION", "Personal", "UniqueNumber", ""))

On Error GoTo 0

Range("D4").Formula = UniqueNumber + 1

SaveSetting "TESTAPPLICATION", "Personal", "UniqueNumber", Range("D4").Value

End Sub

Sub DeleteUserInfoFromRegistry()

' deletes information in the Registry from

' HKEY_CURRENT_USER\Software\VB and VBA Program Settings\TESTAPPLICATION

On Error Resume Next

DeleteSetting "TESTAPPLICATION" ' delete all information

'DeleteSetting "TESTAPPLICATION", "Personal" ' delete one section

'DeleteSetting "TESTAPPLICATION", "Personal", "Birthdate" ' delete one key

On Error GoTo 0

End Sub