I am trying to create a VB macro in MS Word in order to automatically format the background colour of content control dropdowns.
I am using a .docm document and setting my content controls like so:
I then selected the 'Macros' button in the developer tab but for some reason I was not able to create a macro via the pop-up as the buttons are greyed out.
I created a new macro via the 'Visual Basic' button the developer tab but it doesn't seem to run.
I think this is due to where the code is being saved, under the 'Normal' header in the editor sidebar, but when I try to select the actual document project I get a pop up error.
My Code
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
If ContentControl.Title = "IssueSeverity" Then
Select Case .Text
Case "CRITICAL"
.Cells(1).Shading.BackgroundPatternColor = wdColorDarkRed
Case "HIGH"
.Cells(1).Shading.BackgroundPatternColor = wdColorRed
Case "MEDIUM"
.Cells(1).Shading.BackgroundPatternColor = wdColorOrange
Case "LOW"
.Cells(1).Shading.BackgroundPatternColor = wdColorGreen
Case "INFO"
.Cells(1).Shading.BackgroundPatternColor = wdColorBlue
Case Else
.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
End Select
End If
End With
End Sub
What do I need to do within Word (latest version) in order to get macros working?
CodePudding user response:
Looks like you may have the same issue solved by this answer here.
It basically talks about write access to the startup folder where the template is located.
Option #1
Copy template OUT of Start Up Folder, right click file and select "Open" You can [run/]debug it.
Option #2
Ensure you have write permission to file in startup folder. Even if you are Admin, if UAC is ON you won't have access - grant your user "full control" or "write access to file" to DOTM file in startup folder.