Borders around a table cell

J

John Svendsen

Hi All:

I'm trying to write a VBA macro that will set all 4 borders around a cell in
a PPT table that is selected with a certain border color and line thickness.

I've tried to record a macro when doin this manually but the recorded macro
is empty!!! I've looked on VBA help but I don't seem to find how to capture
teh selected cells and how to assing the border (I usually get help from a
recorded macro...).

Could someone please shed some light o what to do?

Thanks so much for your kind help and attention

Rgds, JS
 
J

John Svendsen

Hi Steve:

Thank you for replying, you examples are quite enlighting as to how
tables/cells in ppt work.

But I think I have a nastier issue, I need to surround two or more adjacent
cells (TextRange fails when selecting 2+ cells), do you have any ideas on
how to go about this?

Again thanks for your help!

Rgds, JS
 
J

John Svendsen

Thank you both Steve and Shyam:

Yup, the plot thickens as complexity increases :)

The problem I see with your examples is that you are able to detect all
selected cells and handle them individually. This is OK if you want to,
let's say, modify background color, but I think there's an issue if you want
to surround the entire selection with borders (using the examples the
borders in the middle of the selected cells would also be set, and not only
the countour of the selection (or have I lost it...)

Shyam, I've been testing your second example and all I get is "The specified
value is out of range" on line "With .GroupItems.Range(CellArray).Fill"
[I've created an 8x4 table and selected two cells)

Again, thanks to you both for your inputs - there's much to lear about
tables in PPT!

Rgds, JS
 
E

Edward

You can use somthing like the following , I just applied the border color red
you can make other changes like border weight or differnt color.

Sub TableBorder()
Dim tbl As Table
Dim Mini As Integer
Dim Maxi As Integer
Dim Minj As Integer
Dim Maxj As Integer
Dim iflag As Boolean
Dim jflag As Boolean


Set tbl = ActiveWindow.Selection.ShapeRange(1).Table
For i = 1 To tbl.Rows.Count
For j = 1 To tbl.Columns.Count
If tbl.Cell(i, j).Selected Then
If iflag = False Then
Mini = i
Maxi = i
iflag = True
Else
Maxi = i
End If
If jflag = False Then
Minj = j
Maxj = j
jflag = True
Else
Maxj = j
End If
End If
Next
Next
If Mini > 0 Then

For y = Minj To Maxj
tbl.Cell(Mini, y).Borders(ppBorderTop).ForeColor.RGB = RGB(255, 0, 0)
tbl.Cell(Maxi, y).Borders(ppBorderBottom).ForeColor.RGB = RGB(255, 0, 0)
Next
For x = Mini To Maxi
tbl.Cell(x, Minj).Borders(ppBorderLeft).ForeColor.RGB = RGB(255, 0, 0)
tbl.Cell(x, Maxj).Borders(ppBorderRight).ForeColor.RGB = RGB(255, 0, 0)
Next
End If
End Sub

--
Best regards,
Edward


John Svendsen said:
Thank you both Steve and Shyam:

Yup, the plot thickens as complexity increases :)

The problem I see with your examples is that you are able to detect all
selected cells and handle them individually. This is OK if you want to,
let's say, modify background color, but I think there's an issue if you want
to surround the entire selection with borders (using the examples the
borders in the middle of the selected cells would also be set, and not only
the countour of the selection (or have I lost it...)

Shyam, I've been testing your second example and all I get is "The specified
value is out of range" on line "With .GroupItems.Range(CellArray).Fill"
[I've created an 8x4 table and selected two cells)

Again, thanks to you both for your inputs - there's much to lear about
tables in PPT!

Rgds, JS

Steve Rindsberg said:
Yes, and thanks for asking. I've added an example to:

Working with PowerPoint tables
http://www.pptfaq.com/FAQ00790.htm

Short version:

If ActiveWindow.Selection.Type is ppSelectionShape, test to see if
Selection.ShapeRange(1).Type is 19 (table).

If so, iterate through the table's cells collection, testing each cell to
see
if its .Selected property is True. If so, it's a selected table cell.
Format
that sukkah.



==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/
 
J

John Wilson

Or (drawing on Shyam and Steve's code)

Sub TableBorder()
Dim tbl As Table
Dim Icol As Integer
Dim Irow As Integer

On Error Resume Next
Set tbl = ActiveWindow.Selection.ShapeRange(1).Table
'exit if no selected table
If Err.Number <> 0 Then Exit Sub
For Irow = 1 To tbl.Rows.Count
For Icol = 1 To tbl.Columns.Count
If tbl.Cell(Irow, Icol).Selected Then
'hide existing borders
For i = 1 To 6
tbl.Cell(Irow,Icol).Borders(i).Visible = msoFalse
Next i
For i = 1 To 4
With tbl.Cell(Irow, Icol).Borders(i)
'set to blue weight =2
..Visible = msoTrue
..ForeColor.RGB = RGB(0, 0, 255)
..Weight = 2
End With
Next i
End If
Next Icol
Next Irow

End Sub


--

john ATSIGN PPTAlchemy.co.uk
Custom vba coding and PPT Makeovers
Free PPT Hints, Tips and Tutorials
http://www.pptalchemy.co.uk/powerpoint_hints_and_tips_tutorials.html




Edward said:
You can use somthing like the following , I just applied the border color red
you can make other changes like border weight or differnt color.

Sub TableBorder()
Dim tbl As Table
Dim Mini As Integer
Dim Maxi As Integer
Dim Minj As Integer
Dim Maxj As Integer
Dim iflag As Boolean
Dim jflag As Boolean


Set tbl = ActiveWindow.Selection.ShapeRange(1).Table
For i = 1 To tbl.Rows.Count
For j = 1 To tbl.Columns.Count
If tbl.Cell(i, j).Selected Then
If iflag = False Then
Mini = i
Maxi = i
iflag = True
Else
Maxi = i
End If
If jflag = False Then
Minj = j
Maxj = j
jflag = True
Else
Maxj = j
End If
End If
Next
Next
If Mini > 0 Then

For y = Minj To Maxj
tbl.Cell(Mini, y).Borders(ppBorderTop).ForeColor.RGB = RGB(255, 0, 0)
tbl.Cell(Maxi, y).Borders(ppBorderBottom).ForeColor.RGB = RGB(255, 0, 0)
Next
For x = Mini To Maxi
tbl.Cell(x, Minj).Borders(ppBorderLeft).ForeColor.RGB = RGB(255, 0, 0)
tbl.Cell(x, Maxj).Borders(ppBorderRight).ForeColor.RGB = RGB(255, 0, 0)
Next
End If
End Sub

--
Best regards,
Edward


John Svendsen said:
Thank you both Steve and Shyam:

Yup, the plot thickens as complexity increases :)

The problem I see with your examples is that you are able to detect all
selected cells and handle them individually. This is OK if you want to,
let's say, modify background color, but I think there's an issue if you want
to surround the entire selection with borders (using the examples the
borders in the middle of the selected cells would also be set, and not only
the countour of the selection (or have I lost it...)

Shyam, I've been testing your second example and all I get is "The specified
value is out of range" on line "With .GroupItems.Range(CellArray).Fill"
[I've created an 8x4 table and selected two cells)

Again, thanks to you both for your inputs - there's much to lear about
tables in PPT!

Rgds, JS

Steve Rindsberg said:
But I think I have a nastier issue, I need to surround two or more
adjacent
cells (TextRange fails when selecting 2+ cells), do you have any ideas on
how to go about this?

Yes, and thanks for asking. I've added an example to:

Working with PowerPoint tables
http://www.pptfaq.com/FAQ00790.htm

Short version:

If ActiveWindow.Selection.Type is ppSelectionShape, test to see if
Selection.ShapeRange(1).Type is 19 (table).

If so, iterate through the table's cells collection, testing each cell to
see
if its .Selected property is True. If so, it's a selected table cell.
Format
that sukkah.


Again thanks for your help!

Rgds, JS

Hi All:

I'm trying to write a VBA macro that will set all 4 borders around a
cell
in
a PPT table that is selected with a certain border color and line
thickness.

I've tried to record a macro when doin this manually but the recorded
macro
is empty!!! I've looked on VBA help but I don't seem to find how to
capture
teh selected cells and how to assing the border (I usually get help
from
a
recorded macro...).

This should help:

Working with PowerPoint tables
http://www.pptfaq.com/FAQ00790.htm

Don't expect your Works-Perfectly-In-2003 table code to work in
PowerPoint
2007, though. Tables+2007+VBA = BadlyBroken

==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/



==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/
 
J

John Svendsen

Hi Edward, Steve and Shyam:

Your help is truly appreciated :)

Thanks so much!

Rgds, John

Edward said:
You can use somthing like the following , I just applied the border color
red
you can make other changes like border weight or differnt color.

Sub TableBorder()
Dim tbl As Table
Dim Mini As Integer
Dim Maxi As Integer
Dim Minj As Integer
Dim Maxj As Integer
Dim iflag As Boolean
Dim jflag As Boolean


Set tbl = ActiveWindow.Selection.ShapeRange(1).Table
For i = 1 To tbl.Rows.Count
For j = 1 To tbl.Columns.Count
If tbl.Cell(i, j).Selected Then
If iflag = False Then
Mini = i
Maxi = i
iflag = True
Else
Maxi = i
End If
If jflag = False Then
Minj = j
Maxj = j
jflag = True
Else
Maxj = j
End If
End If
Next
Next
If Mini > 0 Then

For y = Minj To Maxj
tbl.Cell(Mini, y).Borders(ppBorderTop).ForeColor.RGB = RGB(255, 0, 0)
tbl.Cell(Maxi, y).Borders(ppBorderBottom).ForeColor.RGB = RGB(255, 0,
0)
Next
For x = Mini To Maxi
tbl.Cell(x, Minj).Borders(ppBorderLeft).ForeColor.RGB = RGB(255, 0,
0)
tbl.Cell(x, Maxj).Borders(ppBorderRight).ForeColor.RGB = RGB(255, 0,
0)
Next
End If
End Sub

--
Best regards,
Edward


John Svendsen said:
Thank you both Steve and Shyam:

Yup, the plot thickens as complexity increases :)

The problem I see with your examples is that you are able to detect all
selected cells and handle them individually. This is OK if you want to,
let's say, modify background color, but I think there's an issue if you
want
to surround the entire selection with borders (using the examples the
borders in the middle of the selected cells would also be set, and not
only
the countour of the selection (or have I lost it...)

Shyam, I've been testing your second example and all I get is "The
specified
value is out of range" on line "With .GroupItems.Range(CellArray).Fill"
[I've created an 8x4 table and selected two cells)

Again, thanks to you both for your inputs - there's much to lear about
tables in PPT!

Rgds, JS

Steve Rindsberg said:
But I think I have a nastier issue, I need to surround two or more
adjacent
cells (TextRange fails when selecting 2+ cells), do you have any ideas
on
how to go about this?

Yes, and thanks for asking. I've added an example to:

Working with PowerPoint tables
http://www.pptfaq.com/FAQ00790.htm

Short version:

If ActiveWindow.Selection.Type is ppSelectionShape, test to see if
Selection.ShapeRange(1).Type is 19 (table).

If so, iterate through the table's cells collection, testing each cell
to
see
if its .Selected property is True. If so, it's a selected table cell.
Format
that sukkah.


Again thanks for your help!

Rgds, JS

Hi All:

I'm trying to write a VBA macro that will set all 4 borders around
a
cell
in
a PPT table that is selected with a certain border color and line
thickness.

I've tried to record a macro when doin this manually but the
recorded
macro
is empty!!! I've looked on VBA help but I don't seem to find how to
capture
teh selected cells and how to assing the border (I usually get help
from
a
recorded macro...).

This should help:

Working with PowerPoint tables
http://www.pptfaq.com/FAQ00790.htm

Don't expect your Works-Perfectly-In-2003 table code to work in
PowerPoint
2007, though. Tables+2007+VBA = BadlyBroken

==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/



==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/
 
E

Edward

This code will alter all the borders in a selected range of cells , he only
needs the outer most border , so he needs to use a logic similar to what I
wrote in my code.
--
Best regards,
Edward


John Wilson said:
Or (drawing on Shyam and Steve's code)

Sub TableBorder()
Dim tbl As Table
Dim Icol As Integer
Dim Irow As Integer

On Error Resume Next
Set tbl = ActiveWindow.Selection.ShapeRange(1).Table
'exit if no selected table
If Err.Number <> 0 Then Exit Sub
For Irow = 1 To tbl.Rows.Count
For Icol = 1 To tbl.Columns.Count
If tbl.Cell(Irow, Icol).Selected Then
'hide existing borders
For i = 1 To 6
tbl.Cell(Irow,Icol).Borders(i).Visible = msoFalse
Next i
For i = 1 To 4
With tbl.Cell(Irow, Icol).Borders(i)
'set to blue weight =2
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 255)
.Weight = 2
End With
Next i
End If
Next Icol
Next Irow

End Sub


--

john ATSIGN PPTAlchemy.co.uk
Custom vba coding and PPT Makeovers
Free PPT Hints, Tips and Tutorials
http://www.pptalchemy.co.uk/powerpoint_hints_and_tips_tutorials.html




Edward said:
You can use somthing like the following , I just applied the border color red
you can make other changes like border weight or differnt color.

Sub TableBorder()
Dim tbl As Table
Dim Mini As Integer
Dim Maxi As Integer
Dim Minj As Integer
Dim Maxj As Integer
Dim iflag As Boolean
Dim jflag As Boolean


Set tbl = ActiveWindow.Selection.ShapeRange(1).Table
For i = 1 To tbl.Rows.Count
For j = 1 To tbl.Columns.Count
If tbl.Cell(i, j).Selected Then
If iflag = False Then
Mini = i
Maxi = i
iflag = True
Else
Maxi = i
End If
If jflag = False Then
Minj = j
Maxj = j
jflag = True
Else
Maxj = j
End If
End If
Next
Next
If Mini > 0 Then

For y = Minj To Maxj
tbl.Cell(Mini, y).Borders(ppBorderTop).ForeColor.RGB = RGB(255, 0, 0)
tbl.Cell(Maxi, y).Borders(ppBorderBottom).ForeColor.RGB = RGB(255, 0, 0)
Next
For x = Mini To Maxi
tbl.Cell(x, Minj).Borders(ppBorderLeft).ForeColor.RGB = RGB(255, 0, 0)
tbl.Cell(x, Maxj).Borders(ppBorderRight).ForeColor.RGB = RGB(255, 0, 0)
Next
End If
End Sub

--
Best regards,
Edward


John Svendsen said:
Thank you both Steve and Shyam:

Yup, the plot thickens as complexity increases :)

The problem I see with your examples is that you are able to detect all
selected cells and handle them individually. This is OK if you want to,
let's say, modify background color, but I think there's an issue if you want
to surround the entire selection with borders (using the examples the
borders in the middle of the selected cells would also be set, and not only
the countour of the selection (or have I lost it...)

Shyam, I've been testing your second example and all I get is "The specified
value is out of range" on line "With .GroupItems.Range(CellArray).Fill"
[I've created an 8x4 table and selected two cells)

Again, thanks to you both for your inputs - there's much to lear about
tables in PPT!

Rgds, JS

But I think I have a nastier issue, I need to surround two or more
adjacent
cells (TextRange fails when selecting 2+ cells), do you have any ideas on
how to go about this?

Yes, and thanks for asking. I've added an example to:

Working with PowerPoint tables
http://www.pptfaq.com/FAQ00790.htm

Short version:

If ActiveWindow.Selection.Type is ppSelectionShape, test to see if
Selection.ShapeRange(1).Type is 19 (table).

If so, iterate through the table's cells collection, testing each cell to
see
if its .Selected property is True. If so, it's a selected table cell.
Format
that sukkah.


Again thanks for your help!

Rgds, JS

Hi All:

I'm trying to write a VBA macro that will set all 4 borders around a
cell
in
a PPT table that is selected with a certain border color and line
thickness.

I've tried to record a macro when doin this manually but the recorded
macro
is empty!!! I've looked on VBA help but I don't seem to find how to
capture
teh selected cells and how to assing the border (I usually get help
from
a
recorded macro...).

This should help:

Working with PowerPoint tables
http://www.pptfaq.com/FAQ00790.htm

Don't expect your Works-Perfectly-In-2003 table code to work in
PowerPoint
2007, though. Tables+2007+VBA = BadlyBroken

==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/



==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top