View Single Post
 
Old 02-25-2019, 10:23 AM
ubrielbryne ubrielbryne is offline Windows 10 Office 2016
Novice
 
Join Date: Feb 2019
Posts: 2
ubrielbryne is on a distinguished road
Cool error 91 object variable or with block variable not set

Hello.

I helped to create a user macro in Word that 6 people in my office are using on their own network profiles with the same version and settings on all of the applications.
When I personally installed the macro for each of them, I tested it and it ran fine.
Now 3 out of six are getting the run-time error '91' object variable or with block variable not set.

The debug shows ElseIf Selection.Style = "H0" Then
to be the point of error.
I have copied the entire problematic sub below. Remember, on the same day, at the same time, the same macro and copies of the same document will run or error on different user profiles.

What do you all think? (Heads up, I am a noob to writing in and using VBA language so go easy on me.)

Sub SLRkeep()
Dim slranswer As String
Dim p As Paragraph
Dim prange As Range
Dim i As Integer
Dim scount As Integer

For Each p In ActiveDocument.Paragraphs
p.Range.Select
If InStr(Selection.Text, SPQRtext) Then
With Selection.Range
If .Sentences.Count > 3 Then
i = 2
scount = .Sentences.Count
Do Until i + 1 = scount
If InStr(.Sentences(i), SPQRtext) = False And _
InStr(.Sentences(i - 1), SPQRtext) = False And _
InStr(.Sentences(i + 1), SPQRtext) = False Then
.Sentences(i).Delete
i = i - 1
scount = scount - 1
End If
i = i + 1
Loop
End If
End With
ElseIf Selection.Style = "H0" Then

ElseIf Selection.Style = "H1a" Then

ElseIf Selection.Style = "H1b" Then

ElseIf Selection.Style = "H2" Then

ElseIf Selection.Style = "H3" Then

ElseIf Selection.Style = "H4" Then

ElseIf Selection.Style = "H5" Then

Else
Selection.Delete
End If
Next p

End Sub
Reply With Quote