Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting memory or disc error message, Why?

Status
Not open for further replies.

nesplb

Programmer
Jul 29, 2003
109
NO
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
 
Maybe this:

At the end, you check to see if you're going over the last paragraph,
If counter >= ActiveDocument.Paragraphs.Count Then
Exit Sub
End If
but only on the "subject" paragraph, ActiveDocument.Paragraphs(counter). Then you set the next paragraph,
Set p2 = ActiveDocument.Paragraphs(counter + 1)

That could get you into trouble.

_________________
Bob Rashkin
 
Are you using Option Explicit? p2 or p3 are not declared.

What does the procedure lagStil "Normal Start", "Normal" do???

You may want to try using more objects. Declare your Styles as style objects.

Also, maybe use a For Each loop, rather than a counter.
Code:
Dim NormalStart As Style
Dim NormalAfter As Style
Dim CurPara As Paragraph
Dim PrevPara As Paragraph
Dim NextPara As Paragraph
Dim ThisDoc As Document

Set ThisDoc = ActiveDocument
Set NormalStart = ThisDoc.Styles("Normal Start")
Set NormalAfter = ThisDoc.Styles("Normal After")
For Each oPara in ThisDoc.Paragraphs
  Select Case InStr(1, oPara.Style, "blah", 0)
     Case 0 ' no blah found
        ' your logic
     Case 1  ' blah IS found
        ' your logic
  End Select
Next

Finally, perhaps move your declarations up BEFORE your start:
Code:
Dim p As Paragraph
Dim nyStil As String

counter = 1
start:
Those variables are declared EVERY time you loop back to start: when you have it as:
Code:
counter = 1
start:
Dim p As Paragraph
Dim nyStil As String
Not sure what the effect of that is, but it seems to me to be better declaring them at the beginning.

faq219-2884

Gerry
My paintings and sculpture
 
Thanks for the tips!
I'll try to refine my code according to these tips and ill tell when I know the result!

The procedure "lagStil" is trying to make a new paragraph style with the name in the first parameter and the basestyle as the second parameter!





Pål Nesteby

PDC-Tangen
Norway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top