Problem with removing single rows from a Word table using Excel VBA

m_in_spain

Board Regular
Joined
Sep 28, 2018
Messages
64
Office Version
  1. 365
Platform
  1. Windows
The continuing saga of getting Excel to update my word document.

After seemingly endless attempts, lots of help from here, I have found the following line of code actually deletes a (bookmarked in Word with same name) row from my word table:

Code:
If docWord.Bookmarks.Exists(xlName.Name) Then docWord.Bookmarks(xlName.Name).Range.Rows.Delete

My problem is that it deletes not only the row i have bookmarked (Bookmark is at the first typing space in the row) but also other rows below it, sometimes 2, sometimes 3. In Word i shade fill some lines to denote a different area, the above code seems to delete all lines down to the shade change.

I have tried, what seems obvious to me, i.e. change Rows to Row, and also leaving out .Range, but each time it then doesn't delete anything.

I need each bookmark to delete one row in word only. Any help much appreciated
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Code:
If docWord.Bookmarks.Exists(xlName.Name) Then docWord.Bookmarks(xlName.Name).Range.Rows(1).Delete
 
Upvote 0
Many thanks again. I have now split my table in word into lots of single lines, as even with the Rows (1) it still managed to delete some other rows, now they are all single row with 1 pt spacing between them it works like a dream thank you. Odd thing was before i split the rows, sometimes it deleted the row, sometimes more than one row and many times deleted nothing! Now it is solved tho, thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,939
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top