Looping through a word doc to delete rows
Looping through a word doc to delete rows
(OP)
I have a word table that is populated by Excel VBA as shown below:-
In some instances it places an "X" in column 1 as shown below
[img https://res.cloudinary.com/engineering-com/image/u...
I use the following code to successfully to delete other rows with the "X", but it is failing to delete these two and I cannot fathom why. Any help apprecaited.
CODE -->
wordDoc.Tables(4).Cell(2, 1).Range.Text = " " & Range("O19").Value & " Way Flush Mounting, Programmable Alarm Annunciator." 'Product code wordDoc.Tables(4).Cell(5, 1).Range.Text = Range("O25").Value 'Window size wordDoc.Tables(4).Cell(8, 1).Range.Text = Range("O13").Value & "W" & Range("O14").Value & "H" 'Panel Size wordDoc.Tables(4).Cell(12, 1).Range.Text = Range("O26").Value 'Pushbutton wordDoc.Tables(4).Cell(14, 1).Range.Text = Range("O19").Value & "A" 'Channel Count wordDoc.Tables(4).Cell(15, 1).Range.Text = Range("P24").Value ' Unarmed wordDoc.Tables(4).Cell(16, 1).Range.Text = Range("R25").Value 'Illumination wordDoc.Tables(4).Cell(17, 1).Range.Text = Range("O27").Value 'RR wordDoc.Tables(4).Cell(18, 1).Range.Text = Range("R26").Value 'Trop wordDoc.Tables(4).Cell(19, 1).Range.Text = Range("O29").Value 'FCV wordDoc.Tables(4).Cell(20, 1).Range.Text = Range("P33").Value 'Comms wordDoc.Tables(4).Cell(21, 1).Range.Text = Range("P32").Value 'GFI wordDoc.Tables(4).Cell(22, 1).Range.Text = Range("L44").Value 'Logo wordDoc.Tables(4).Cell(24, 1).Range.Text = Range("O28").Value 'SEC wordDoc.Tables(4).Cell(29, 1).Range.Text = Range("Q76").Value 'Option wordDoc.Tables(4).Cell(30, 3).Range.Text = Range("B3").Value 'Part number
In some instances it places an "X" in column 1 as shown below
[img https://res.cloudinary.com/engineering-com/image/u...
I use the following code to successfully to delete other rows with the "X", but it is failing to delete these two and I cannot fathom why. Any help apprecaited.
CODE -->
With wordDoc.Tables(4) For r = 1 To .Rows.Count If .Cell(r, c).Range.Text Like "*" & "X" & "*" Then wordDoc.Tables(4).Rows(r).Delete End If Next r End With
RE: Looping through a word doc to delete rows
CODE
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: Looping through a word doc to delete rows
RE: Looping through a word doc to delete rows
From the provided code (Like "*" & "X" & "*"), it looks to me that you delete the rows when the cell contains X, so not only X by itself, but also "Malcolm X", "X-Factor", "ABCXYZ", etc.
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: Looping through a word doc to delete rows
@strongm
Great job! Thank you both for your suggestion it worked straight away
RE: Looping through a word doc to delete rows
If one or more of the posts helped you with your issue, consider clicking the "Great post!" link.
Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
RE: Looping through a word doc to delete rows
Out of 169 posting encounters on Tek-Tips, the OP had expressed with a little purple star only twice in 20 years.
Skip,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Looping through a word doc to delete rows
CODE
Cheers
Paul Edstein
[Fmr MS MVP - Word]