Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
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
  #2  
Old 02-25-2019, 11:15 AM
ubrielbryne ubrielbryne is offline Windows 10 Office 2016
Novice
 
Join Date: Feb 2019
Posts: 2
ubrielbryne is on a distinguished road
Default Solved

In-house tech had a stroke of genius and realized that we use alot of hidden text/variable style features in our documents. Show hidden text selection is a requirement for some of the parts of the whole macro to run correctly.

So, turning on the show hidden text option for the document makes the variables for the styles and other hidden text properties available for the macro to utilize.

YAY!
Reply With Quote
Reply

Tags
microsoft word, run-time 91, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Variable or With block variable not set Raza Excel Programming 8 01-15-2015 12:19 AM
Run Time Error '91': Object variable or With block variable not set using Catalogue Mailmerge Berryblue Mail Merge 1 11-13-2014 05:36 PM
Run-time error 91 object variable or with block variable not set JUST ME Word VBA 4 03-25-2014 06:56 AM
object variable or with block variable not set MJP143 Excel 1 02-11-2013 05:07 AM
Run-time error '91': Object variable or With block variable not set tinfanide Excel Programming 2 06-10-2012 10:17 AM


All times are GMT -7. The time now is 04:01 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft