Hi!
I have a sub that is supposed to loop throug all the paragraphs in the document, but with larger documents I get the error "-This method or porperty is unavailable because there is a disc or memory error".
Is there something in my code that messes up the memory that I should write different to awoid this?
The Sub is called from another Sub.
Heres the code, It does some paragraph style checking and editing. The error comes on the line that sets p, p2 or p3:
Sub fiksNormalStart()
Dim counter As Long
counter = 1
start:
Dim p As Paragraph
Dim nyStil As String
Set p = ActiveDocument.Paragraphs(counter)
Set p2 = ActiveDocument.Paragraphs(counter + 1)
'Some processing"
If InStr(1, p.Style, "Tit", vbBinaryCompare) Then
If (p2.Style.NameLocal = "Normal") Then
On Error GoTo feil
lagStil "Normal Start", "Normal"
feil:
p2.Style = ActiveDocument.Styles("Normal Start")
End If
'Some processing
ElseIf InStr(1, p.Style, "L ", vbBinaryCompare) And InStr(1, p.Style, "Uavs", vbBinaryCompare) = 0 Then
Set p3 = ActiveDocument.Paragraphs(counter - 1)
'Some processing
If p3.Style.NameLocal <> p.Style.NameLocal And InStr(1, p3.Style, "Start", vbBinaryCompare) = 0 And InStr(1, p3.Style, "Uavs", vbBinaryCompare) = 0 Then
nyStil = p.Style + " Start"
On Error GoTo feil2
lagStil nyStil, "Normal"
feil2:
p.Style = ActiveDocument.Styles(nyStil)
End If
'Some processing
If p2.Style = "Normal" Then
On Error GoTo feil3
lagStil "Normal After", "Normal"
feil3:
p2.Style = ActiveDocument.Styles("Normal After")
End If
'Some processing
ElseIf InStr(1, p.Style, "Slutt", vbBinaryCompare) Then
If (p2.Style.NameLocal = "Normal") Then
On Error GoTo feil4
lagStil "Normal After", "Normal"
feil4:
p2.Style = ActiveDocument.Styles("Normal After")
End If
End If
counter = counter + 1
If counter >= ActiveDocument.Paragraphs.Count Then
Exit Sub
End If
Set p = Nothing
GoTo start
End Sub
In advance thanks!
Pål Nesteby, Oslo Norway
Pål Nesteby
PDC-Tangen
Norway
I have a sub that is supposed to loop throug all the paragraphs in the document, but with larger documents I get the error "-This method or porperty is unavailable because there is a disc or memory error".
Is there something in my code that messes up the memory that I should write different to awoid this?
The Sub is called from another Sub.
Heres the code, It does some paragraph style checking and editing. The error comes on the line that sets p, p2 or p3:
Sub fiksNormalStart()
Dim counter As Long
counter = 1
start:
Dim p As Paragraph
Dim nyStil As String
Set p = ActiveDocument.Paragraphs(counter)
Set p2 = ActiveDocument.Paragraphs(counter + 1)
'Some processing"
If InStr(1, p.Style, "Tit", vbBinaryCompare) Then
If (p2.Style.NameLocal = "Normal") Then
On Error GoTo feil
lagStil "Normal Start", "Normal"
feil:
p2.Style = ActiveDocument.Styles("Normal Start")
End If
'Some processing
ElseIf InStr(1, p.Style, "L ", vbBinaryCompare) And InStr(1, p.Style, "Uavs", vbBinaryCompare) = 0 Then
Set p3 = ActiveDocument.Paragraphs(counter - 1)
'Some processing
If p3.Style.NameLocal <> p.Style.NameLocal And InStr(1, p3.Style, "Start", vbBinaryCompare) = 0 And InStr(1, p3.Style, "Uavs", vbBinaryCompare) = 0 Then
nyStil = p.Style + " Start"
On Error GoTo feil2
lagStil nyStil, "Normal"
feil2:
p.Style = ActiveDocument.Styles(nyStil)
End If
'Some processing
If p2.Style = "Normal" Then
On Error GoTo feil3
lagStil "Normal After", "Normal"
feil3:
p2.Style = ActiveDocument.Styles("Normal After")
End If
'Some processing
ElseIf InStr(1, p.Style, "Slutt", vbBinaryCompare) Then
If (p2.Style.NameLocal = "Normal") Then
On Error GoTo feil4
lagStil "Normal After", "Normal"
feil4:
p2.Style = ActiveDocument.Styles("Normal After")
End If
End If
counter = counter + 1
If counter >= ActiveDocument.Paragraphs.Count Then
Exit Sub
End If
Set p = Nothing
GoTo start
End Sub
In advance thanks!
Pål Nesteby, Oslo Norway
Pål Nesteby
PDC-Tangen
Norway