Problem converting VBScript to VBA

  • Thread starter Thread starter Tod
  • Start date Start date
T

Tod

I have a vbscript that tests the BreakOnAllErrors setting
in the registry. If it's set to 1, the script sets it to 0
(zero). I wanted to put it in VBA but the compiler chokes
on this line:

Set WSHShell = WScript.CreateObject("WScript.Shell")

Since I can't create that object I guess the rest of the
code would also have a problem.

My code is posted below. My ultimate idea is to have this
code run in the Workbook BeforeClose event. Could someone
tell me how to convert this so it'll run in VBA?

thanx,

tod


Dim WSHShell, str_data, ETSetting
Set WSHShell = WScript.CreateObject("WScript.Shell")

'If the registry is locked, unlock it before changing the
setting.
str_data = WSHShell.RegRead
("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\S
ystem\DisableRegistryTools")
If str_data = 1 Then

'If the settings is 1, make it 0.
WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentV
ersion\Policies\System\DisableRegistryTools", 0
ETSettin = WSHShell.RegRead
("HKEY_CURRENT_USER\Software\Microsoft\VBA\6.0
\Common\BreakOnAllErrors")
If ETSetting = 1 Then

WSHShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\VBA
\6.0\Common\BreakOnAllErrors", 0, "REG_DWORD"
End If

WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentV
ersion\Policies\System\DisableRegistryTools", 1
Else
ETSettin = WSHShell.RegRead
("HKEY_CURRENT_USER\Software\Microsoft\VBA\6.0
\Common\BreakOnAllErrors")
If ETSetting = 1 Then

WSHShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\VBA
\6.0\Common\BreakOnAllErrors", 0, "REG_DWORD"
End If

WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentV
ersion\Policies\System\DisableRegistryTools", 1
End If
 
Back
Top