Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-29-2012, 12:29 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Please tell me it doesn't take 7 statements to turn table borders off Windows XP Please tell me it doesn't take 7 statements to turn table borders off Office 2007
Competent Performer
Please tell me it doesn't take 7 statements to turn table borders off
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default Please tell me it doesn't take 7 statements to turn table borders off

I want to add code to a macro to turn off all but the bottom border in the header row of a table. I started the macro recorder, selected the first row, turned off all borders, then turned the bottom border back on. Here's the code I got:

Code:
Sub Macro1()
  Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
  Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
  Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
  Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
  Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
  Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
  Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
  With Selection.Borders(wdBorderBottom)
    .LineStyle = Options.DefaultBorderLineStyle
    .LineWidth = Options.DefaultBorderLineWidth
    .Color = Options.DefaultBorderColor
  End With
End Sub
Is there really no wdBorderAll variable or something equivalent?
Reply With Quote
  #2  
Old 01-29-2012, 04:09 PM
macropod's Avatar
macropod macropod is offline Please tell me it doesn't take 7 statements to turn table borders off Windows 7 64bit Please tell me it doesn't take 7 statements to turn table borders off Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Jennifer,

You could use a loop:
Code:
Sub Demo()
Dim i As Long
With Selection.Tables(1)
  With .Rows(1).Range
    For i = 1 To .Borders.Count
      .Borders(i).LineStyle = wdLineStyleNone
    Next
    .Borders(wdBorderBottom).LineStyle = Options.DefaultBorderLineStyle
  End With
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-29-2012, 05:41 PM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Please tell me it doesn't take 7 statements to turn table borders off Windows XP Please tell me it doesn't take 7 statements to turn table borders off Office 2007
Competent Performer
Please tell me it doesn't take 7 statements to turn table borders off
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

That's pretty clever. I never would have thought of that.

So I take it there is no wdBordersAll or something like that, right?
Reply With Quote
  #4  
Old 01-29-2012, 05:56 PM
macropod's Avatar
macropod macropod is offline Please tell me it doesn't take 7 statements to turn table borders off Windows 7 64bit Please tell me it doesn't take 7 statements to turn table borders off Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Jennifer Murphy View Post
So I take it there is no wdBordersAll or something like that, right?
You could use something like:
ActiveDocument.Tables(1).Rows(1).Borders.Enable = False
but that would remove the bottom border from the row as well. You might remedy that with code like:
Code:
With ActiveDocument.Tables(1)
  .Rows(1).Borders.Enable = False
  .Rows(2).Borders.Enable = True
End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-25-2012, 08:13 AM
sydneytroz sydneytroz is offline Please tell me it doesn't take 7 statements to turn table borders off Windows 7 64bit Please tell me it doesn't take 7 statements to turn table borders off Office 2012
Novice
 
Join Date: Jul 2012
Posts: 1
sydneytroz is on a distinguished road
Default

Quote:
Originally Posted by Jennifer Murphy View Post
So I take it there is no wdBordersAll or something like that, right?
Since the border styles are stored in an array or some sort of indexed list, it looks like the other wd* variables are just indices, so a wdBordersAll wouldn't make sense.

If VBA was kept up with the .NET languages, you could do something like (I'm not familiar with VB .NET, so this is borrowing from the C# syntax)
Code:
Selection.Borders.ForEach(x => x.LineStyle = wdLineStyleNone)
...but that will probably never happen.
Reply With Quote
  #6  
Old 07-25-2012, 03:12 PM
macropod's Avatar
macropod macropod is offline Please tell me it doesn't take 7 statements to turn table borders off Windows 7 64bit Please tell me it doesn't take 7 statements to turn table borders off Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Yes, one could loop through the collection, but that still requires turning on/off seven separate border attributes.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Please tell me it doesn't take 7 statements to turn table borders off showing results of If statements in a mail merge m&co Mail Merge 3 01-06-2012 07:27 PM
Please tell me it doesn't take 7 statements to turn table borders off Word VBA: add borders to active table tinfanide Word VBA 2 12-02-2011 05:53 AM
Insert table button doesn't work in Outlook 2010 e-mail message ironwoods Outlook 0 08-02-2010 12:24 PM
Converting document to PDF but table of contents doesn't work luthers Word 0 07-30-2009 03:29 PM
IF statements that shifts to right. kent Excel 0 01-19-2006 02:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:48 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