PDA

View Full Version : Solved: Simple table question (I think)



TrippyTom
07-10-2006, 10:49 AM
Hi all,

How do I add a table and give it a name in VBA so I can change that specific table's column and row properties for the border colors?

I tried using the .addtable feature, but it's not allowing me to name it. Should I be doing it a different way?

Thanks in advance,
TT

Here's my code:

Sub myTable()
Dim mySlide As Integer
Dim sh As Integer
Dim myCol As Variant
mySlide = ActiveWindow.View.Slide.SlideIndex
ActivePresentation.Slides(mySlide).Shapes.AddTable NumRows:=3, _
NumColumns:=4, Left:=50, Top:=300, Width:=100, Height:=100
'Currently, this affects any table in the current slide. I would like
'to make it only affect the table I just added by somehow naming it.
With ActivePresentation.Slides(mySlide)
For sh = 1 To .Shapes.Count
If .Shapes(sh).HasTable Then
For Each myCol In .Shapes(sh).Table.Columns
myCol.Width = 50
Next myCol
End If
Next
End With
End Sub

Norie
07-10-2006, 11:17 AM
Tom

Why not create a reference to the table?

mySlide = ActiveWindow.View.Slide.SlideIndex
Set tb = ActivePresentation.Slides(mySlide).Shapes.AddTable(NumRows:=3, _
NumColumns:=4, Left:=50, Top:=300, Width:=100, Height:=100)
'Currently, this affects any table in the current slide. I would like
'to make it only affect the table I just added by somehow naming it.
For Each myCol In tb.Table.Columns
myCol.Width = 50
Next myCol

TrippyTom
07-10-2006, 11:29 AM
thanks very much, Norie. :)
I knew it was something simple. I just couldn't remember the proper syntax to do something like that (thus, I wasn't sure how to search for it).

Thanks a ton :)
I'm not familiar with the PowerPoint model of vba, so it's like learning it all over again. :doh: