Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA - is it ok to read values from the registry?

Status
Not open for further replies.

slwolf8

Technical User
Apr 23, 2001
82
US
I would like to have my Word XP macro grab a value from the registry in order to determine if a certain network printer here at work is installed on their machine. Does reading registry values in VBA cause any sort of corruption? I had previously written a macro for use here at work that wrote a value to the registry and after people used it, some of the users reported errors when trying to use certain unrrelated documents "the document could not be registered" microsoft says that this error occurs when the registry has been corrupted. I just wanted to make sure my code did not corrupt the registry. here was the code i used:

Dim MySettings As Variant
MySettings = GetSetting(appname:="Printer", Section:="Docketing", Key:="Exists")
DPFPrinter = "DPFprint"
CurrentPrinter = Application.ActivePrinter

If MySettings = 1 Then
Documents.Add Template:=NormalTemplate.FullName
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
frmMain.Show
Else:
On Error Resume Next

Application.ActivePrinter = DPFPrinter
myPrinter = Left(Application.ActivePrinter, 8)

'Check to see if the docketing printer is installed

If myPrinter <> DPFPrinter Then
MsgBox "You do not have the docketing printer installed. Please contact the Help Desk."
Exit Sub
End If

Application.ActivePrinter = CurrentPrinter

SaveSetting appname:="Printer", Section:="Docketing", Key:="Exists", setting:=1

Documents.Add Template:=NormalTemplate.FullName

If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If

frmMain.Show
End If
 
I've never heard of the registry getting corrupted just by reading it, so you're probably ok on that one. Writing to the registry is another matter, and I suppose it is possible that your code did corrupt it somehow (although I don't know how).

Anyone else got input on this one?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top