You can mark your macro with CODE tags by using the [#] icon and pasting the macro between them
These are not the most elegant way, but should work
Option Explicit
Sub abc()
UserForm1.OB_Verksamhet_Lantbruk.Visible = False
With ThisDocument.Bookmarks
If .Exists("Kapitel_EKP_Lantbruk1") Then GoTo OK
If .Exists("Kapitel_EKP_Lantbruk2") Then GoTo OK
If .Exists("Rutin_Eldning_i_det_fria") Then GoTo OK
If .Exists("Rutin_Elinstallationer") Then GoTo OK
If .Exists("Rutin_Gödningsmedel") Then GoTo OK
If .Exists("Rutin_Heta_Arbeten_Lantbruk") Then GoTo OK
If .Exists("Rutin_Hästskoning") Then GoTo OK
If .Exists("Rutin_Högtryckstvättning") Then GoTo OK
If .Exists("Rutin_Inomgårdsutrustning") Then GoTo OK
If .Exists("Rutin_Insatsplan") Then GoTo OK
If .Exists("Rutin_Lagring") Then GoTo OK
If .Exists("Rutin_Motordrivna_fordon") Then GoTo OK
If .Exists("Rutin_Släckutrustning") Then GoTo OK
If .Exists("Rutin_Torkfläktar") Then GoTo OK
If .Exists("Rutin_Uppvärmning") Then GoTo OK
If .Exists("Rutin_Utrymning") Then GoTo OK
OK:
UserForm1.OB_Verksamhet_Lantbruk.Visible = True
End With
End Sub
Sub def
Dim b As Boolean
b = False
With ThisDocument.Bookmarks
b = b Or .Exists("Kapitel_EKP_Lantbruk1")
b = b Or .Exists("Kapitel_EKP_Lantbruk2")
b = b Or .Exists("Rutin_Eldning_i_det_fria")
b = b Or .Exists("Rutin_Elinstallationer")
b = b Or .Exists("Rutin_Gödningsmedel")
b = b Or .Exists("Rutin_Heta_Arbeten_Lantbruk")
b = b Or .Exists("Rutin_Hästskoning")
b = b Or .Exists("Rutin_Högtryckstvättning")
b = b Or .Exists("Rutin_Inomgårdsutrustning")
b = b Or .Exists("Rutin_Insatsplan")
b = b Or .Exists("Rutin_Lagring")
b = b Or .Exists("Rutin_Motordrivna_fordon")
b = b Or .Exists("Rutin_Släckutrustning")
b = b Or .Exists("Rutin_Torkfläktar")
b = b Or .Exists("Rutin_Uppvärmning")
b = b Or .Exists("Rutin_Utrymning")
End With
UserForm1.OB_Verksamhet_Lantbruk.Visible = b
End Sub
Yes, VBA does like (usually) to have an EndIf for every If
You can put skip the End If when the whole conditional is on one line like I did
With indenting, you can see the bracketing
Sub def()
If ThisDocument.Bookmarks.Exists("Kapitel_EKP_Lantbruk1") = False Then
If ThisDocument.Bookmarks.Exists("Kapitel_EKP_Lantbruk2") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Eldning_i_det_fria") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Elinstallationer") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Gödningsmedel") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Heta_Arbeten_Lantbruk") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Hästskoning") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Högtryckstvättning") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Inomgårdsutrustning") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Insatsplan") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Lagring") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Motordrivna_fordon") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Släckutrustning") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Torkfläktar") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Uppvärmning") = False Then
If ThisDocument.Bookmarks.Exists("Rutin_Utrymning") = False Then
UserForm1.OB_Verksamhet_Lantbruk.Visible = False
Else
UserForm1.OB_Verksamhet_Lantbruk.Visible = True
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
I'm not sure that the way you had it will do what I think you want.
If ALL .Exists = False then .Visible = False is finally executed
If ANY .Exists = True, then the If/Then goes to the End If and the .Visible = True is bypassed