Microsoft Office Tutorials and References
In Depth Information
Windows API Calls
The message box will display the path and filename of the graphic file (or an empty string if
wallpaper isn’t used).
Writing to the Registry
The WriteRegistry function writes a value to the Registry at a specified location. If the
operation is successful, the function returns True ; otherwise, it returns False . WriteRegistry
takes the following arguments (all of which are strings):
h RootKey : A string that represents the branch of the Registry to address. This string may
be one of the following:
h Path : The full path in the Registry. If the path doesn’t exist, it is created.
h RegEntry : The name of the Registry category to which the value will be written. If it
doesn’t exist, it is added.
h RegVal : The value that you’re writing.
Here’s an example that writes a value representing the time and date Excel was started to the
Registry. The information is written in the area that stores Excel’s settings.
RootKey = “hkey_current_user”
Path = “software\microsoft\office\14.0\excel\LastStarted”
RegEntry = “DateTime”
RegVal = Now()
If WriteRegistry(RootKey, Path, RegEntry, RegVal) Then
msg = RegVal & “ has been stored in the registry.”
Else msg = “An error occurred”
If you store this routine in the ThisWorkbook module in your personal macro workbook, the
setting is automatically updated whenever you start Excel.