ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Edit Word Table from Excel using vba code (https://www.excelbanter.com/excel-programming/396672-edit-word-table-excel-using-vba-code.html)

John_R_Fry

Edit Word Table from Excel using vba code
 
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


[email protected]

Edit Word Table from Excel using vba code
 
On 31 Aug, 10:40, John_R_Fry
wrote:
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



All times are GMT +1. The time now is 10:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com