Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2011, 11:57 AM
Ulodesk Ulodesk is offline Formatting macro Windows 7 Formatting macro Office 2007
Word 2013 Expert Cert
Formatting macro
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Formatting macro

Using Word 2007 in a corporate environment, my colleague DTPs and I regularly have to reformat tables to our template design. Although I have stored two designs as Quick Parts and, with one internal borders exception, can apply this design, I am trying to create a macro to format any existing table this way. I am only somewhat familiar with VBA and hope someone can solve this riddle:

I have no luck starting the macro recorder and then using the New Table Style dialogue. The borders come out much too thick and the dialogue insists on reopening after the table is formatted when I run the macro. Therefore, have recorded my macro with an unformatted table in place, going through steps to format it by selection. When I run the macro, however, it calls up debug and points to the first diagonal borders line in the macro, which I have highlighted in bold blue below. I have no idea what the problem is. Here's the macro. Any help will be most appreciated.

Sub KTableH()
'
' KTableH Macro
'
'
Selection.Tables(1).Select
With Selection.Tables(1)
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle


.LineWidth = wdLineWidth050pt
.Color = 8284228
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = 8284228
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = 8284228
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = 8284228
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = 8284228
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = 8284228
End With
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = 8284228
End With
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.SelectRow
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = 8284228
With Selection.Cells
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = 8284228
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = 8284228
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = 8284228
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = 8284228
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = -603914241
End With
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = -603914241
End With
End Sub
Reply With Quote
  #2  
Old 01-26-2011, 07:11 PM
macropod's Avatar
macropod macropod is offline Formatting macro Windows 7 32bit Formatting macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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 Ulodesk,

When posting code, please use code tags.

Whilst I'm not sure what your table design goals are, the following appears to replicate what your code was doing:
Code:
Sub KTableH()
Dim i As Integer
With Options
  .DefaultBorderLineStyle = wdLineStyleSingle
  .DefaultBorderLineWidth = wdLineWidth050pt
  .DefaultBorderColor = 8284228
End With
With Selection.Tables(1)
  For i = 1 To 8
    Select Case i
      Case 1, 3 - 8
        With .Borders(i)
          .LineStyle = Options.DefaultBorderLineStyle
          .LineWidth = Options.DefaultBorderLineWidth
          .Color = Options.DefaultBorderColor
        End With
      Case Else
        With .Borders(i)
          .LineStyle = wdLineStyleNone
        End With
    End Select
  Next i
  With .Rows(1).Range
    With .Shading
      .Texture = wdTextureNone
      .ForegroundPatternColor = wdColorAutomatic
      .BackgroundPatternColor = 8284228
    End With
    .Borders.Shadow = False
    With .Cells.Borders(wdBorderVertical)
      .LineStyle = wdLineStyleSingle
      .LineWidth = wdLineWidth050pt
      .Color = -603914241
    End With
  End With
End With
With Options
  .DefaultBorderLineStyle = wdLineStyleSingle
  .DefaultBorderLineWidth = wdLineWidth050pt
  .DefaultBorderColor = -603914241
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-28-2011, 08:21 AM
Ulodesk Ulodesk is offline Formatting macro Windows 7 Formatting macro Office 2007
Word 2013 Expert Cert
Formatting macro
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Missing borders

Paul,

Thanks for your reply. I read your posts often and continue to learn. I'll have to look up tag use, since I don't know what you mean by using them when posting code.

In this case, the code you supplied formats only the header row fill and internal vertical borders, albeit in the correct colors. The table we use actually has half-point borders of the same color (68/104/126) on all cells (the white internals in the header row excepted), and the font in the header row should be white and boldface.

Anyway, it was just an idea. I'm always looking for improved ways to learn and to encourage our staff to use the shortcuts Word offers. At some point, perhaps I'll find the time to learn VBA. Would that Word had the kind of power with tables that InDesign has.

Cordially,
Ulodesk
Reply With Quote
  #4  
Old 01-28-2011, 01:45 PM
macropod's Avatar
macropod macropod is offline Formatting macro Windows 7 32bit Formatting macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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 Ulodesk,

To manage font attributes, you should create a Style with them (probably a paragraph Style in this case) and apply that Style to the cells concerned.

When you say:
Quote:
supplied formats only the header row fill and internal vertical borders, albeit in the correct colors
does that mean you wanted all cells formatted this way?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 04-10-2012, 04:35 PM
ubns ubns is offline Formatting macro Windows 7 32bit Formatting macro Office 2010 32bit
Competent Performer
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

Tt throughs an Syntax error - Sub Ktable not defined.
Reply With Quote
  #6  
Old 04-10-2012, 05:09 PM
macropod's Avatar
macropod macropod is offline Formatting macro Windows 7 64bit Formatting macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

That suggests you've added the code somewhere it shouldn't be (like inside another sub)!!
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 04-10-2012, 05:56 PM
ubns ubns is offline Formatting macro Windows 7 32bit Formatting macro Office 2010 32bit
Competent Performer
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

i am just creating a new module and placing in that.
Reply With Quote
  #8  
Old 04-10-2012, 06:12 PM
macropod's Avatar
macropod macropod is offline Formatting macro Windows 7 64bit Formatting macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

The macro runs fine for me. I simply created a new module, copied the code from post #2 & pasted it into the new module, created a table in the document, then ran the macro. No errors.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 04-10-2012, 06:30 PM
ubns ubns is offline Formatting macro Windows 7 32bit Formatting macro Office 2010 32bit
Competent Performer
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

Thanks mate, I tried again and this time it worked. I must have done something wrong earlier.

Regards

Last edited by macropod; 04-10-2012 at 06:36 PM. Reason: Stripped off content for separate thread
Reply With Quote
  #10  
Old 04-10-2012, 06:37 PM
macropod's Avatar
macropod macropod is offline Formatting macro Windows 7 64bit Formatting macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Please don't add new requests to other peoples' threads. I've split your new request off to a separate thread.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting macro Help with a macro Takket Word VBA 2 03-28-2014 04:58 PM
need a macro that does the following atomsk Word VBA 0 07-05-2010 07:29 AM
Please help Jarrod Word 1 06-05-2010 06:31 AM
Macro help NEHicks503 Excel 0 04-16-2010 07:29 AM
Formatting macro Formatting Help caution5697 Word 3 04-22-2009 11:53 PM

Other Forums: Access Forums

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