Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2017, 09:10 PM
cltay87 cltay87 is offline Delete Empty Table Rows Windows 7 32bit Delete Empty Table Rows Office 2010 32bit
Novice
Delete Empty Table Rows
 
Join Date: Feb 2017
Posts: 7
cltay87 is on a distinguished road
Default Delete Empty Table Rows

Hi there,



I've been using a VBA macro to delete empty table rows that runs effectively in the document's body/content. Document as attached.

However, I can't run the same VBA macro in the header that used textbox to contain the table rows.

I've been trying many ways to make it work, but can't.

Appreciate if anyone here can help me with this.

Thank you in advance.
Attached Files
File Type: doc vba test.doc (177.0 KB, 12 views)
Reply With Quote
  #2  
Old 02-27-2017, 12:04 AM
gmayor's Avatar
gmayor gmayor is offline Delete Empty Table Rows Windows 10 Delete Empty Table Rows Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The simplest solution is to convert the text box to a frame. If you want to keep the space (and if you did why remove the rows in an unbordered table) set the frame height to exact - otherwise set it to auto so it will shrink (as in the attached). You can then loop through the story ranges and remove the empty rows, modifying your code to process the range rather than the document.
Attached Files
File Type: doc vba test.doc (185.0 KB, 10 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 02-27-2017, 12:43 AM
cltay87 cltay87 is offline Delete Empty Table Rows Windows 7 32bit Delete Empty Table Rows Office 2010 32bit
Novice
Delete Empty Table Rows
 
Join Date: Feb 2017
Posts: 7
cltay87 is on a distinguished road
Default

Thanks Gmayor, it works well. But it always gave run-time error '13' : Type mismatch after the macro ends.

When i debug, Set oStory = oShape.TextFrame is highlighted.

Not sure what's wrong.
Reply With Quote
  #4  
Old 02-27-2017, 01:30 AM
gmayor's Avatar
gmayor gmayor is offline Delete Empty Table Rows Windows 10 Delete Empty Table Rows Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

My fault, I sent you an unsaved earlier version

The sub should be

Code:
Sub ProcessRanges()
Dim oStory As Range
   For Each oStory In ActiveDocument.StoryRanges
        DeleteEmptyRows oStory
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                DeleteEmptyRows oStory
            Wend
        End If
    Next oStory
    Set oStory = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 02-27-2017, 04:23 AM
cltay87 cltay87 is offline Delete Empty Table Rows Windows 7 32bit Delete Empty Table Rows Office 2010 32bit
Novice
Delete Empty Table Rows
 
Join Date: Feb 2017
Posts: 7
cltay87 is on a distinguished road
Default

It works perfect! Thank you gmayor!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Empty Table Rows Macro to delete all empty rows from all tables braddgood Word VBA 15 10-02-2015 01:54 PM
Delete Empty Table Rows Delete row with empty cel in a table vibor Word VBA 9 05-03-2015 05:42 AM
Delete Empty Table Rows Delete All empty Rows - Print - Undo all Rows deleted Bathroth Word VBA 1 10-01-2014 01:40 PM
Creating VBA Code to Delete Empty Column in Table Faugs Word VBA 5 08-07-2014 03:29 PM
Delete Empty Table Rows Macro to delete rows with all empty cells ubns Excel Programming 2 08-14-2012 02:01 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft