« More posts arriving shortly ... :) | Main | Take Your Data Traveling: Use Charts and Diagrams in Multiple Programs »
Hi, everyone! I just read a great article that many of us can identify with. Have you ever been charged with picking out a computer for family members, parents in particular?
Juliana Aldous Atkinson, Product Planner at Microsoft Learning, wrote a great article about how to buy a computer for your parents. There's a lot of good advice and several great links ... check it out:
6 steps when buying your parents a computer
For more from Juliana, check out her blog.
And, speaking of blogs, where are those postings I've promised? Yeah, I know. I have a list of those I've promised to post -- and I will make good. I have 3 projects to get through this week (it's CRAZY) so I didn't get time to post technical goodies this past weekend as I said I would ... but things should lighten up for me a bit by next week, and I will catch up over the holidays on technical tips including the long-promised presentation vs. science approaches to charting data ... and a list of favorite VBA macro tips.
Meanwhile, always feel free to post technical questions in comments to whatever my most recent post is and I'll respond asap. (Check out a fun one in comments in the post directly below these ... I love it when 1 line of code can save you hours of stressing over a document -- don't you?? ;-)
Happy Tuesday everyone!!
Steph
Posted by Stephanie
TrackBack URL for this entry:
http://www.arouet.net/cgi-bin/mt/mt-tb.cgi/145
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)
Comments
In Powerpoint, I am trying to create a macro that will create a 3 column table. I need the font to be 18 pt Arial. Also, need to be sure the font color is WHITE. Can you provide me with information on how this can be done. here is my code that creates the table.
ActivePresentation.Slides(1).Shapes _
.AddTable NumRows:=1, NumColumns:=3, Left:=20, _
Top:=300, Width:=650, Height:=100
Thanks Denise
Posted by: Denise | December 21, 2005 11:00 AM
Hi, Denise,
Sure. Well, you're off to a good start. PowerPoint VBA help actually gives you all the info you need on this one. In VBA, search for 'working with tables' - there is a help article by that name that will answer your questions exactly.
Now, in that article, it has you specifying the shape index in order to apply the font formatting to it (font is a cell attribute within a table -- so the sample macro in that article loops through the cells of the table to apply the font formatting).
If you want to act on the selection as you create the table, just adjust your initial code slightly to select the table as it is inserted. Here is that code:
ActivePresentation.Slides(1).Shapes.AddTable(1, 3, 20, 300, 650, 100).Select
Hope that helps. Let me know if the VBA article leaves any part of this unanswered for you.
Best,
Steph
Posted by: Stephanie | December 21, 2005 12:22 PM
Hi Stephanie
I am still confused about this. The "select" part does not seem to be working. I am still unable to get the font to set to 18pt for the table on creation. Is it possible to have the table font set for 18pt as well as alignment to Center. I tried to follow the steps in the article working with tables but nothing is working.
Thanks Denise
Posted by: Denise | January 3, 2006 11:18 AM
Hi, Denise,
Please post the full code of your macro in a comment and we'll get to the bottom of it :)
Happy New Year -
Steph
Posted by: Stephanie | January 3, 2006 12:13 PM
Here is my code: Something is not right:
ActivePresentation.Slides(1).Shapes.AddTable(1, 2, 250, 300, 400, 100).Select
With ActivePresentation.Slides(1).Shapes(4).Table
For Each cl In .Rows(1).Cells
cl.Shape.font = 18
Next cl
End With
Posted by: Denise | January 3, 2006 02:16 PM
Hi,
Well -- two things going on. First of all, you left out part of the required code for the font property - font isn't a property of shape as you used it -- you need shape.textframe.textrange.font ...
Keep in mind that if your code doens't give you autocomplete menus of available options when you type a period in a line of code, there is probably something invalid in your code. Always select from the autocomplete menus so that you know the object, property, or method you're writing exists. If you use Option Explicit at the top of your module (good idea to always use this), you will have to declare all of your variables - as I did in the code I gave you here - but you will then get autocomplete menus even when you use variables ... which is INCREDIBLY helpful. You can either type Option Explicit at the top of the module, or in the VB editor go to Tools, Options, Editor and select Require variable declaration - then the VB editor will add Option Explicit for you every time you create a module.
But, also, there is a glitch in PowerPoint VBA that you're running into... Until text exists in the cell, PowerPoint VBA doesn't recognize the shape as having a text range to format (I call it a glitch because you can do it from the UI, but not from code).
So, you need to drop some text in, format the text, then remove the text.
Using the selection option I gave you earlier would work in this case -- though the way you wrote your code, it doesn't act on a selection... and that's fine. But, so that you don't have to hard code a shape number or write code to find the shape number every time the macro is run, I'll suggest naming the shape as you insert it instead -- that way it will work regardless of the number of shapes on your slide.
This code will work:
Dim cl As Cell
Dim ar As Row
ActivePresentation.Slides(1).Shapes.AddTable(1, 2, 250, 300, 400, 100).Name = "mytable"
With ActivePresentation.Slides(1).Shapes("mytable").Table
For Each ar In .Rows
For Each cl In ar.Cells
With cl.Shape.TextFrame.TextRange
.Text = "t"
.Font.Size = 18
.Text = ""
End With
Next cl
Next ar
End With
Posted by: Stephanie | January 3, 2006 02:55 PM
Thanks for the code Stephanie. Now I am trying to use the HASTABLE code to verify if a table exist and if it does then delete it. I used code from the "working with tables" and I get an error message on the code: here is the code
Dim sh As Shapes
With ActivePresentation.Slides(1)
For sh = 1 To .Shapes.Count
If .Shapes(sh).HasTable Then
.Select
.Delete
End If
Next
End With
My object here is to see if existing table exist in the same location, if it does delete it and insert a new table via the macro to insert table.
Posted by: Denise | January 10, 2006 02:27 PM
Hi, Denise,
Well, there are a couple of things going on here. The main issue is the way you're using variables. I suspect the error you're getting is "type mismatch" or something similar ... that means there is a problem in the way your variables are declared. There are a few things in your code that are not following VBA rules.
The other issue with this is a glitch with the Delete method here. When one table is deleted, the loop will stop running. So, the macro requires a check for the number of tables and then a nested loop to get them all.
My code below uses the Type property of the Shape object instead of the HasTable method. The reason is that with HasTable, you have to select each shape on the slide to check it. With the Type property, you don't have to -- less work for the code to do (and less code to write).
I'd suggest reviewing VBA syntax a bit and then review this code -- it will make this sort of thing easier. If you don't already have it, download the PowerPoint VBA language reference from MSDN: http://www.microsoft.com/downloads/details.aspx?familyid=9C0AA0F6-A164-4F87-A01A-1BC17E698E22&displaylang=en
Try to get familiar with the following terms and how they are correctly written\used: object, property, method, variable (as well as declaring variables), constant, Do loop, For-Next loop. Once you understand how to use variables and how the basic types of loops differ (when to use which), this type of thing should get a lot easier.
Hope this helps!
Steph
Here's the code:
Sub checktabls()
Dim sh As Shape
Dim myI, myQ As Integer
myI = 0
myQ = 1
For Each sh In ActivePresentation.Slides(1).Shapes
If sh.Type = msoTable Then
myI = myI + 1
End If
Next sh
Do While myQ <= myI
For Each sh In ActivePresentation.Slides(1).Shapes
If sh.Type = msoTable Then
sh.Delete
End If
Next sh
myQ = myQ + 1
Loop
End Sub
Posted by: Stephanie | January 23, 2006 11:27 AM