Edit Word Table from Excel using vba code

G

Guest

Hi,

Office 2003.
I'm trying to delete paragraph marks from inside the tables of a Word
Document opened via VBA code from Excel but Excel keeps crashing on me. Can
anyone suggest a correction please? Each table is selected ok but doesn't
seem to like the ".Replacement.Text" line in code below:-

Sub ReplaceParaMarksInTable()
Dim intTables As Integer
Dim intX As Integer

If ActiveDocument.Tables.Count >= 1 Then
intTables = ActiveDocument.Tables.Count
For intX = 3 To intTables
With ActiveDocument.Tables(intX).Range
.Select
.Find.ClearFormatting
.Find.Replacement.ClearFormatting
With .Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
.Find.Execute

End With
Next intX
End If
End Sub
 
A

aidan.heritage

Hi,

Office 2003.
I'm trying to delete paragraph marks from inside the tables of a Word
Document opened via VBA code from Excel but Excel keeps crashing on me. Can
anyone suggest a correction please? Each table is selected ok but doesn't
seem to like the ".Replacement.Text" line in code below:-

Sub ReplaceParaMarksInTable()
Dim intTables As Integer
Dim intX As Integer

If ActiveDocument.Tables.Count >= 1 Then
intTables = ActiveDocument.Tables.Count
For intX = 3 To intTables
With ActiveDocument.Tables(intX).Range
.Select
.Find.ClearFormatting
.Find.Replacement.ClearFormatting
With .Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
.Find.Execute

End With
Next intX
End If
End Sub

Are you sure it's that line - I would suspect the wdFindContinue
myself - this is a Word constant, and should be replaced with it's
numeric value of 1
 

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