Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-25-2011, 10:44 PM
tinfanide tinfanide is offline Word VBA: add borders to active table Windows 7 64bit Word VBA: add borders to active table Office 2010 32bit
Expert
Word VBA: add borders to active table
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Word VBA: add borders to active table

Code:
Sub table()

    With ActiveDocument
    
    .Tables.Add Range:=Selection.Range, _
    NumRows:=3, _
    NumColumns:=3, _
    DefaultTableBehavior:=wdWord8TableBehavior
    
' I want to select this table
' and add borders
    
    End With

    With ActiveDocument.Tables(2)
    
        .Borders(wdBorderTop).LineStyle = wdLineStyleSingle
        .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
        .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
        .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
        .Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle
        .Borders(wdBorderVertical).LineStyle = wdLineStyleSingle
        .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleSingle
        .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleSingle
    
    End With


End Sub
Please see the comments above.


Please help, thx!
Reply With Quote
  #2  
Old 11-30-2011, 04:33 AM
macropod's Avatar
macropod macropod is offline Word VBA: add borders to active table Windows 7 64bit Word VBA: add borders to active table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 Tinfanide,

This is easiest if you assign the new table to a variable:
Code:
Sub AddTable()
Dim oTbl
With ActiveDocument
  Set oTbl = .Tables.Add(Range:=Selection.Range, NumRows:=3, _
    NumColumns:=3, DefaultTableBehavior:=wdWord8TableBehavior)
  With oTbl
    .Borders(wdBorderTop).LineStyle = wdLineStyleSingle
    .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
    .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
    .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
    .Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle
    .Borders(wdBorderVertical).LineStyle = wdLineStyleSingle
    .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleSingle
    .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleSingle
  End With
End With
Set oTbl = Nothing
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-02-2011, 05:53 AM
tinfanide tinfanide is offline Word VBA: add borders to active table Windows 7 64bit Word VBA: add borders to active table Office 2010 32bit
Expert
Word VBA: add borders to active table
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Yes, just like giving the table an id.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
letterhead design with column and borders jiquvox Word 1 10-11-2011 11:18 AM
Word VBA: add borders to active table BORDERS are too big rockerz Word 3 06-08-2011 06:17 PM
Drag Button which refers to the active Word document to Explorer DRob Word 0 10-03-2010 06:40 AM
Word VBA: add borders to active table Tables and Borders/Gridlines Jukee Word 1 06-22-2010 02:49 AM
I need to use alternating borders sarajev Word 1 11-19-2009 01:56 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:44 PM.


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