Problem with macro

K

ken

I've created a macro to modify the Index table of a document. It has 3
parts:

1 Find the beginning of the Index table.
2 Find a specified string and cut it from the table.
3 Find a specified string (x number of times), move the cursor up/down
specified times and insert paste data.

Sub find_index()
' find the start of the index table
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 7")
Selection.Find.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = "index"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Find.ClearFormatting
End Sub

Sub find_cut(cut_str As String)
' find cut point
' first; find the beginning of the index table
find_index

With Selection.Find
.Text = cut_str
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' select the entire line
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Cut
End Sub

Sub find_ins(ins_str As String, Rpt_Cnt As Integer, UpDown As Integer)
' find insert point
With Selection.Find
.Text = ins_str
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

Dim cntr
cntr = Rpt_Cnt
Do
Selection.Find.Execute
cntr = cntr - 1
Loop Until cntr <= 0

' move the cursor to the beginning of the line
Selection.HomeKey Unit:=wdLine

cntr = UpDown
If (UpDown < 0) Then
Do
Selection.MoveDown Unit:=wdLine, Count:=1
cntr = cntr + 1
Loop Until cntr >= 0
ElseIf (UpDown > 0) Then
Do
Selection.MoveDown Unit:=wdLine, Count:=1
cntr = cntr - 1
Loop Until cntr <= 0
End If
' insert cut string
Selection.Paste
End Sub


I'm having 2 problems that I'm stuck on. The first problem has to do with
the call of the subroutine to find the insertion point (find_ins)

find_ins ( "Test API", 0, 0 )

I get a error message: "Compile error \ Expected: =". I don't program very
much with VBA (once every 5 years) and suspect that I'm forgetting something
basic here but what?

The other problem I'm having has to do with strings that have
leading/trailing double quotes. My macro won't compile with them.

Any ideas?

TIA,
Ken Erickson
 
K

ken

OK, I knew that I forgot something that was causing me problems: Added the
Call statement which fixes my first problem. However, I'm still having a
problem with passing a quoted string to a subroutine. Any ideas?

TIA,
Ken Erickson
 
D

Doug Robbins - Word MVP

Hi Ken,

Use Chr(34)

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
K

ken

The problem turns out to be rather simple to solve. You have to escape the
double quote with another double quote.

Thanks Doug.
 

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