Tab width adjustment for Smart Indenter for Office 2010/13

In Office 2010/13 SmartIndentor fails to pick up the VBA Editor tab width from the registry.
The procedure writes the VBA editor tab width into the old registry key for Office 2003 so that Smart Indentor will then be able to read it.

'------------------------------------------------------------------------------- 
' Procedure : Update_SmartIndenter_Tab_Width
' Author    : Hartmut Gruenhagen 
' Date      : 31-Jan-14 
' Purpose   : In Office 2010/13 SmartIndentor fails to pick up the 
'             VBA Editor tab width from the registry. 
'             The procedure writes the VBA editor tab width into a 
'             that Smart Indentor will then be able to read it.
'------------------------------------------------------------------------------- 
' 
Public Sub Update_SmartIndenter_Tab_Width()
   Dim myWS As Object
   Dim intEditorTabWidth As Integer
   Dim intIndenterTabWidth As Integer
   On Error Resume Next
   Set myWS = CreateObject("WScript.Shell")
   intEditorTabWidth = myWS.RegRead("HKEY_CURRENT_USER\Software\Microsoft\VBA\7.0\Common\TabWidth")
   If intEditorTabWidth = 0 Then
      intEditorTabWidth = myWS.RegRead("HKEY_CURRENT_USER\Software\Microsoft\VBA\7.1\Common\TabWidth")
   End If
   If intEditorTabWidth = 0 Then intEditorTabWidth = 3
   myWS.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\VBA\6.0\Common\TabWidth", intEditorTabWidth, "REG_DWORD"
   intIndenterTabWidth = myWS.RegRead("HKEY_CURRENT_USER\Software\Microsoft\VBA\6.0\Common\TabWidth")
   If intIndenterTabWidth = intEditorTabWidth Then
      MsgBox "The tab width for SmartIndenter has been updated successfully in the registry." & vbCrLf & vbCrLf & _
             "The new tab width is " & intIndenterTabWidth
   Else
      MsgBox "Oops! This didn't work." & vbCrLf & vbCrLf & _
             "Writing the VBA Editor tab width to the registry for SmartIndenter failed."
   End If
End Sub

2 comments


Leave a comment