+ Reply to Thread
Results 1 to 3 of 3

Clear Word Table Row from Excel VBA

Hybrid View

  1. #1
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Clear Word Table Row from Excel VBA

    I'm trying to clear the data out of a Word table row without deleting the row and have already wasted half a day on it, including extensive internet search, but nothing seems to work. I haven't found any code to delete the contents of a row with a single command. I'm trying to select the row and then delete the data, but the code I'm using gets a run-time error - Object doesn't support this property or method. Here's that code:

    wdDoc.Tables(TblID).rows(tblrow).select
    wdDoc.Tables(TblID).selection.delete
    
    Also tried with same error result:
    
    wdDoc.selection.delete
    It selects the row, but apparently the Delete method doesn't work in that context.

    I tried recording a macro in Word to see how it did it, but you can't select a table row while a macro is recording. Help, please!

  2. #2
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Clear Word Table Row from Excel VBA

    Did you try:

    wdDoc.Tables(TblID).Rows(tblrow).Select
    Selection.Delete
    I not familiar with Word VBA, but it worked for me.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Clear Word Table Row from Excel VBA

    Hello natefarm,

    In VBA it is rare that you need to select an object before performing an action on it. The code below will Clear the cell contents of the specified Table row and not delete the row from the table.
                For Each c In wdDoc.Tables(TblID).Rows(tblrow).Cells
                    c.Range.Delete 1, Len(c.Range.Text)
                Next c
    Last edited by Leith Ross; 07-26-2013 at 06:10 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Convert Word to Excel based upon Word Table of Contents
    By jcappuccino7 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-06-2013, 01:25 PM
  2. Replies: 7
    Last Post: 04-21-2009, 02:50 AM
  3. Word table into Excel
    By mikeb350z in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 12-05-2008, 03:00 AM
  4. Word table to excel
    By mikeb350z in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 12-01-2008, 12:28 PM
  5. Replies: 2
    Last Post: 02-11-2005, 06:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1