weird problem and intersting solution

H

Harvey

I have a macrobook with a lot of VBA code (over 60 procedures) with over 400
useres. Only a few useres used to get error 91 when they were trying to use
one of the macros which shows a userform with list of chpters and gives the
user the option of deleting them or moving them around. I coudn't find the
solution until some of them told me when they turn on paragraph marks(using
show /hide button on toolbar) they can use the macro and they don't get the
error!!!
Anyone knows any connection between these two?
Thanks :)
 
J

Jean-Guy Marcil

Harvey was telling us:
Harvey nous racontait que :
I have a macrobook with a lot of VBA code (over 60 procedures) with
over 400 useres. Only a few useres used to get error 91 when they
were trying to use one of the macros which shows a userform with list
of chpters and gives the user the option of deleting them or moving
them around. I coudn't find the solution until some of them told me
when they turn on paragraph marks(using show /hide button on toolbar)
they can use the macro and they don't get the error!!!
Anyone knows any connection between these two?
Thanks :)

You would have to show us the code.
But I suspect that it has to do with the fact that you are probably using
the Selection object instead of the range one.
Or it has to do with Hidden text.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Harvey

Hi Jean
Its a very long sub but I send the part I think creates the problem.
Thanks you for your time.

Dim Sec As Section, Par As Paragraph, myrange As Range, sTitle As String
Dim isec As Integer

ReplaceSoftReturns
isec = 1
For Each Sec In ActiveDocument.Sections
Select Case iChapType
Case 1, 2
If (Sec.Range.Paragraphs(1).Range.Style = "Chapter Title") Or _
(Sec.Range.Paragraphs(1).Range.Style = "Chapter Title for
Appendix/Exhibit") Then
Set myrange = Sec.Range.Paragraphs(1).Range
myrange.End = myrange.End - 1
sTitle = myrange
ReDim Preserve ChapListArr(isec)
ChapListArr(isec).sTitle = sTitle
ChapListArr(isec).isec = Sec.Index
isec = isec + 1
End If
Case 3, 4
If (Sec.Range.Paragraphs(1).Range.Style = "Chapter Title for
Sub-Chapter") Then
For Each Par In Sec.Range.Tables(1).Cell(4,
2).Range.Paragraphs
If Par.Style = "Sub-Chapter Title (Active)" Then
Set myrange = Par.Range
myrange.End = myrange.End - 1
If myrange = "" Then GoTo skippar
sTitle = myrange
'Call CheckUniqueness(sTitle)
ReDim Preserve ChapListArr(isec)
ChapListArr(isec).sTitle = sTitle
ChapListArr(isec).isec = Sec.Index
isec = isec + 1
End If
skippar:
Next Par
End If

Case Else
GoTo finish
End Select
Next Sec

If iChapType = 2 Then
ReDim Preserve ChapListArr(isec)
ChapListArr(isec).sTitle = "OR DESIGNATE AS LAST CHAPTER"
ChapListArr(isec).isec = ActiveDocument.Sections.Count
GoTo finish
End If

finish:
RestoreSoftReturns
m_iChapType = iChapType
'---------------------------------------------
 
H

Harvey

its a very long sub but im sending the part which creates the problem.

Dim Sec As Section, Par As Paragraph, myrange As Range, sTitle As String
Dim isec As Integer

ReplaceSoftReturns
isec = 1
For Each Sec In ActiveDocument.Sections
Select Case iChapType
Case 1, 2
If (Sec.Range.Paragraphs(1).Range.Style = "Chapter Title") Or _
(Sec.Range.Paragraphs(1).Range.Style = "Chapter Title for
Appendix/Exhibit") Then
Set myrange = Sec.Range.Paragraphs(1).Range
myrange.End = myrange.End - 1
sTitle = myrange
'Call CheckUniqueness(sTitle)
ReDim Preserve ChapListArr(isec)
ChapListArr(isec).sTitle = sTitle
ChapListArr(isec).isec = Sec.Index
isec = isec + 1
End If
Case 3, 4
If (Sec.Range.Paragraphs(1).Range.Style = "Chapter Title for
Sub-Chapter") Then
For Each Par In Sec.Range.Tables(1).Cell(4,
2).Range.Paragraphs
If Par.Style = "Sub-Chapter Title (Active)" Then
Set myrange = Par.Range
myrange.End = myrange.End - 1
If myrange = "" Then GoTo skippar
sTitle = myrange
'Call CheckUniqueness(sTitle)
ReDim Preserve ChapListArr(isec)
ChapListArr(isec).sTitle = sTitle
ChapListArr(isec).isec = Sec.Index
isec = isec + 1
End If
skippar:
Next Par
End If

Case Else
GoTo finish
End Select
Next Sec

If iChapType = 2 Then
ReDim Preserve ChapListArr(isec)
ChapListArr(isec).sTitle = "OR DESIGNATE AS LAST CHAPTER"
ChapListArr(isec).isec = ActiveDocument.Sections.Count
GoTo finish
End If

finish:
RestoreSoftReturns
m_iChapType = iChapType
 
J

Jean-Guy Marcil

Harvey was telling us:
Harvey nous racontait que :
Hi Jean
Its a very long sub but I send the part I think creates the problem.
Thanks you for your time.

Have you tried yourself?
I mean, did you try running the macro with Show All On and then Off?
Do you also get the error?

If so, which line of code chokes?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Harvey

yes I got the same error #91 on my computer also but as i said when i turn on
the paragraph marks i don't get the error and this code works fine. I moved
the entire document to a new documnet (using macros) and now I don't get this
error even with paragraph marks off. So Im wondering what could be the
connection between formatting marks showing and getting this error message?!
 
J

Jean-Guy Marcil

Harvey was telling us:
Harvey nous racontait que :
yes I got the same error #91 on my computer also but as i said when i
turn on the paragraph marks i don't get the error and this code works
fine. I moved the entire document to a new documnet (using macros)
and now I don't get this error even with paragraph marks off. So Im
wondering what could be the connection between formatting marks
showing and getting this error message?!

When you debugged the error, which code line is highlighted by the debugger?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Harvey

I have another sub which calles the sub I sent it previously and it has error
handler so I don't really know which code generates this error.
Im pasting the other sub also which loads the form.

Private Sub UserForm_Initialize()
'cancel is true unless user clicks 'OK' and no error
g_blnChapterCancel = True
Dim lblSource, lblDestination As String
Dim iChapType As Integer, isec As Integer
On Error GoTo errorhandler
'1 - Chapter New 11 - Sub New
'2 - Chapter Insert 12 - Sub Insert
'3 - Chapter Delete 13 - Sub Delete
'4 - Chapter Copy 14 - Sub Copy
'5 - Chapter Change Title 15 - Sub Change Title
'6 - Chapter Move 16 - Sub Move

'load appropriate captions (see above for g_iType list)
iChapType = 1 'this is 1 until specified otherwise - for chapter use
'2 - adds 'DESIGNATE AS LAST CHAPTER' to list
'3 - for Sub-Chapter use
'4 - adds '****subchapter line
Select Case g_iType
Case 1
lblSource = "Location of New Chapter? Insert BEFORE..."
iChapType = 2
Case 2
lblSource = "Location of Chapter? Insert BEFORE..."
iChapType = 2
Case 3
lblSource = "DELETE chapter..."
Case 4
lblSource = "COPY chapter..."
Case 5
lblSource = "Select the Chapter Title to be changed..."
Case 6
lblSource = "MOVE Chapter..."
lblDestination = "BEFORE..."
Me.Height = 126
Me.cmdOk.Top = 82
Me.cmdCancel.Top = 82
Me.lblDestination.Visible = True
Me.cmbDestination.Visible = True
Case 13
lblSource = "Delete Sub-Chapter..."
iChapType = 3
Case 14
lblSource = "Copy Sub-Chapter..."
iChapType = 3
Case 15
lblSource = "Select the Sub-Chapter Title to be changed..."
iChapType = 3
End Select
Me.lblSource = lblSource
Me.lblDestination = lblDestination

'get and load chapter list
GetChapList iChapType
For isec = 1 To UBound(ChapListArr)
Me.cmbSource.AddItem ChapListArr(isec).sTitle
Next isec
'get second list if MOVE
If (g_iType = 6) Then
iChapType = 2
GetChapList iChapType
For isec = 1 To UBound(ChapListArr)
Me.cmbDestination.AddItem ChapListArr(isec).sTitle
Next isec
End If
GoTo finish

errorhandler:
Select Case Err.Number
Case 0
' Do nothing
Case 91
MsgBox g_constrERROR & Err.Number & vbCr & vbCr & "Error loading
list of chapters or sub-chapters." & vbCr & _
g_constrROUTINE & "frmChapterList", _
vbInformation + vbExclamation, _
g_constrTITLE
Case Else
MsgBox g_constrERROR & Err.Number & vbCr & vbCr &
Err.Description & vbCr & _
g_constrROUTINE & "frmChapterList", _
vbInformation + vbExclamation, _
g_constrTITLE
End Select
'reset values
g_iType = 0
ReDim ChapListArr(1)
Unload Me
finish:
Me.Show
End Sub
 
J

Jean-Guy Marcil

Harvey was telling us:
Harvey nous racontait que :
I have another sub which calles the sub I sent it previously and it
has error handler so I don't really know which code generates this
error.
Im pasting the other sub also which loads the form.

If you really want to get to the bottom of this, you need to step through
the code.

From the VB Editor, locate the sub that starts the procedure and place the
cursor inside that sub. Hit F8 to debug step by step until you see where it
jumps to the error handler. The line before the one that does not get
executed (because of the jump to the error handler) will be the one that
threw the error.


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Harvey

Thanks Jean,
As I said I transfered the whole document to a new one and I don't get
this error anymore so I can't check the error anymore I was just wondering if
anyone knows any connecetion between showing paragraph marks and error #91 ?
Thank you for looking at my code if this error happenes again I'll post it
again.
have a wonderful day !
Thanks :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top