Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-20-2017, 04:47 PM
Alvaro.passi Alvaro.passi is offline Maybe is impossible? Windows 10 Maybe is impossible? Office 2016
Novice
Maybe is impossible?
 
Join Date: Jul 2017
Posts: 6
Alvaro.passi is on a distinguished road
Default Maybe is impossible?

I have more than 500 tables in Word. All of them have horizontal green borders at the top and bottom of the table, and some horizontal lines inside the table. Because of a mistake, some lines inside the same table and between tables have different green colors.
I need to unify the color of visible borders of all tables to the same green (RGB:0,128,0).
All the tables have the first row completelly merged. Tables have diferent numbers of rows and columns (see example attached).

I have been trying to fix this issue with many codes, without any success.

For example, this code only works with the top border:

Sub colorBorders()
Dim i As Integer
Dim tabl As Table
For Each tabl In ActiveDocument.Tables ' iterate all the tables
For i = 1 To tabl.Borders.Count ' iterate all borders for each table
tabl.Borders(i).Color = RGB(0, 128, 0)
Next i


Next tabl
End Sub

Anyone knows? Thanks!!
Attached Files
File Type: docx Tablas para subir a foro.docx (20.5 KB, 13 views)
Reply With Quote
  #2  
Old 07-20-2017, 08:28 PM
gmaxey gmaxey is offline Maybe is impossible? Windows 7 32bit Maybe is impossible? Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Will take a while to run, but seems to work:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/20/2017
Dim oTbl As Table
Dim oCell As Cell
  For Each oTbl In ActiveDocument.Tables
    For Each oCell In Selection.Tables(1).Range.Cells
      If Not oCell.Borders(wdBorderTop).Color = RGB(0, 128, 0) Then
        oCell.Borders(wdBorderTop).Color = RGB(0, 128, 0)
      End If
      If Not oCell.Borders(wdBorderBottom).Color = RGB(0, 128, 0) Then
        oCell.Borders(wdBorderBottom).Color = RGB(0, 128, 0)
      End If
    Next oCell
  Next oTbl
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-21-2017, 02:00 AM
Alvaro.passi Alvaro.passi is offline Maybe is impossible? Windows 10 Maybe is impossible? Office 2016
Novice
Maybe is impossible?
 
Join Date: Jul 2017
Posts: 6
Alvaro.passi is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Will take a while to run, but seems to work:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/20/2017
Dim oTbl As Table
Dim oCell As Cell
  For Each oTbl In ActiveDocument.Tables
    For Each oCell In Selection.Tables(1).Range.Cells
      If Not oCell.Borders(wdBorderTop).Color = RGB(0, 128, 0) Then
        oCell.Borders(wdBorderTop).Color = RGB(0, 128, 0)
      End If
      If Not oCell.Borders(wdBorderBottom).Color = RGB(0, 128, 0) Then
        oCell.Borders(wdBorderBottom).Color = RGB(0, 128, 0)
      End If
    Next oCell
  Next oTbl
lbl_Exit:
  Exit Sub
End Sub
You are the best! Thanks so much!! It works slow, but perfect!
Reply With Quote
  #4  
Old 07-21-2017, 10:30 AM
Alvaro.passi Alvaro.passi is offline Maybe is impossible? Windows 10 Maybe is impossible? Office 2016
Novice
Maybe is impossible?
 
Join Date: Jul 2017
Posts: 6
Alvaro.passi is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Will take a while to run, but seems to work:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/20/2017
Dim oTbl As Table
Dim oCell As Cell
  For Each oTbl In ActiveDocument.Tables
    For Each oCell In Selection.Tables(1).Range.Cells
      If Not oCell.Borders(wdBorderTop).Color = RGB(0, 128, 0) Then
        oCell.Borders(wdBorderTop).Color = RGB(0, 128, 0)
      End If
      If Not oCell.Borders(wdBorderBottom).Color = RGB(0, 128, 0) Then
        oCell.Borders(wdBorderBottom).Color = RGB(0, 128, 0)
      End If
    Next oCell
  Next oTbl
lbl_Exit:
  Exit Sub
End Sub
I have a problem...if I select the whole document, the macro only works with the first table. How can I loop through all of the tables?
Reply With Quote
  #5  
Old 07-21-2017, 11:20 AM
Alvaro.passi Alvaro.passi is offline Maybe is impossible? Windows 10 Maybe is impossible? Office 2016
Novice
Maybe is impossible?
 
Join Date: Jul 2017
Posts: 6
Alvaro.passi is on a distinguished road
Default

Solved! just have to change Selection.Tables(1) to oTabl
THANKS!!

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/20/2017
Dim oTbl As Table
Dim oCell As Cell
For Each oTbl In ActiveDocument.Tables
For Each oCell In oTbl.Range.Cells
If Not oCell.Borders(wdBorderTop).Color = RGB(0, 128, 0) Then
oCell.Borders(wdBorderTop).Color = RGB(0, 128, 0)
End If
If Not oCell.Borders(wdBorderBottom).Color = RGB(0, 128, 0) Then
oCell.Borders(wdBorderBottom).Color = RGB(0, 128, 0)
End If
Next oCell
Next oTbl
lbl_Exit:
Exit Sub
End Sub
Reply With Quote
  #6  
Old 07-22-2017, 04:50 AM
gmaxey gmaxey is offline Maybe is impossible? Windows 7 32bit Maybe is impossible? Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Sorry about that. I had started with just the selected table and when it worked I was short of time and just through in the For Each Loop.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 07-24-2017, 09:45 AM
Alvaro.passi Alvaro.passi is offline Maybe is impossible? Windows 10 Maybe is impossible? Office 2016
Novice
Maybe is impossible?
 
Join Date: Jul 2017
Posts: 6
Alvaro.passi is on a distinguished road
Default

Thanks Greg for your kind help!!
Reply With Quote
Reply

Tags
borders, vba, word tables



Similar Threads
Thread Thread Starter Forum Replies Last Post
Maybe is impossible? Deleting last page really impossible??? trstew Word 4 07-14-2016 05:24 AM
assing task impossible multitrust Outlook 1 06-18-2014 01:01 AM
Maybe is impossible? Why is it impossible to find anything in Word?!?!? GreatBigBore Word 1 09-03-2012 04:30 PM
A problem that is impossible to solve... A F 1 G 3 Word 0 09-17-2010 09:32 AM
This may be impossible, but I thought I would ask... 00don Excel 2 03-11-2009 09:02 AM

Other Forums: Access Forums

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