PDA

View Full Version : Solved: Deleteing Word Chart Rows if all cells are empty



rob0923
09-02-2009, 08:34 AM
Hi,

I nkow this is more of a word question, but Since its being run from excel I would need excel to do the work, but is it possible to delete entire word chart rows from an excel vba?

Thanks for you time.

Kenneth Hobs
09-02-2009, 10:06 AM
If you can do in Word's VBA, you can do it in Excel's VBA. Record your macro in Word and then modify it in Excel.

rob0923
09-02-2009, 06:32 PM
Thanks Kenneth.

I tried your input. I did try what you mentioned and got the following.

Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=10, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.Cells.Delete ShiftCells:=wdDeleteCellsEntireRow
Selection.TypeBackspace

That does help, but I have multiple nested tables and what I need if if all the cell are empty then to delete, but if one of the 10 cell have something inputed it will be left alone.

I am looking for something for the following, but for rows.

rob0923
10-01-2009, 05:24 PM
Hi incase anyone is looking to solve this type of problem. It can be found at Word MVP.

http://word.mvps.org/FAQs/MacrosVBA/DeleteEmptyRows.htm

macropod
10-02-2009, 12:55 AM
Hi Rob,

Here's a different approach, for a Word table linked to an Excel range:
1. name the source range in Excel
2. Make sure the range is linked in Word. To do this, copy it from Excel, then, in Word, use Edit|Paste Special and chhose the 'paste link' option. Choos an appropriate paste format (eg Excel object or RTF).
3. After pasting, use Format|object and change the layout, if necessary, to in-line with text.
4. Press Shift-F9 to expose the field code. It'll look something like:
{LINK Excel.Sheet.# "C:\\Users\\Rob\\Documents\\Excel Table.xls" "Sheet1!R1C1:R10C10" \a \r}
5. Change the range reference (Sheet1!R1C1:R10C10) to your Excel range name
6. Press F9 to update the field
7. If you had to change the layout from 'square' in step 3, change it back to 'square' if you want.
8. Make sure the 'update automatic links at open' option is checked, under Tools|Options|General.

From now on, the Word table will update to reflect changes to the Excel range. If required range Excel range expands or contracts, simply re-define it and the changed range will again be reflected in the Word document.