VBA macro for making a text box


S

SteveK

Hi,

In Powerpoint 2003 I want to have a button on one of the toolbars that
places a box on the page.
I want the box to have:
- white fill
- black text
- Arial-Normal
- 12pt
- 2 lines of text (using a soft return to get to the second line)
- outline of the box 2 pt, black
- Order position on top of everything else
- Size of the box should be just large enough to accommadate the known text
that will go in the box.
- position of the text should probably just go in the center of the page and
then the user will move the box to where needed on the page. - but it would
be cool if there is a trick that allows positioning after pushing the
toolbar button.

I don't understand VBA but I can sort of induce a few things from looking at
the code that is generated when I record a macro of this:

Sub DPN_textbox2()
'
' Macro recorded 1/31/2005 by sk
'


ActivePresentation.SlideMaster.TextStyles.Item(Type:=ppDefaultStyle).Levels(
Level:=1).ParagraphFormat.Alignment = ppAlignLeft

ActivePresentation.SlideMaster.TextStyles.Item(Type:=ppDefaultStyle).Levels(
Level:=1).Font.Name = "Arial"

ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizo
ntal, 264, 264, 78, 21.625).Select
ActiveWindow.Selection.ShapeRange.TextFrame.WordWrap = msoTrue
With ActiveWindow.Selection.TextRange.ParagraphFormat
.LineRuleWithin = msoTrue
.SpaceWithin = 1
.LineRuleBefore = msoTrue
.SpaceBefore = 0.5
.LineRuleAfter = msoTrue
.SpaceAfter = 0
End With
With ActiveWindow.Selection.ShapeRange
.Fill.ForeColor.SchemeColor = ppBackground
.Fill.Visible = msoTrue
.Fill.Solid
End With
With ActiveWindow.Selection.ShapeRange
.Line.Weight = 2.0
.Line.Visible = msoTrue
.Line.Style = msoLineSingle
End With
With ActiveWindow.Selection.ShapeRange
.Line.ForeColor.SchemeColor = ppForeground
.Line.Visible = msoTrue
End With

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1,
Length:=0).Select
With ActiveWindow.Selection.TextRange
.Text = "DPN yyyyyy" + Chr$(CharCode:=11) + "QTY= X"
With .Font
.Name = "Arial"
.Size = 12
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.SchemeColor = ppForeground
End With
End With
With ActiveWindow.Selection.ShapeRange
.ScaleWidth 1.23, msoFalse, msoScaleFromTopLeft
.ScaleHeight 0.91, msoFalse, msoScaleFromTopLeft
End With
ActiveWindow.Selection.ShapeRange.ScaleWidth 0.94, msoFalse,
msoScaleFromTopLeft
ActiveWindow.Selection.ShapeRange.ScaleWidth 0.93, msoFalse,
msoScaleFromTopLeft
ActiveWindow.Selection.ShapeRange.ZOrder msoBringToFront
ActiveWindow.Selection.SlideRange.Shapes("Text Box 9").Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
ActiveWindow.Selection.ShapeRange.ZOrder msoSendBackward
End Sub

Anybody want to comment on what I could do to this code to make it better?

One thing: what is text box 9? It's probably the ninth text box that I've
put on that page or something and I don't want it in the macro, do I?

Thanks,
Steve Krause
two letter abbreviation at dolby.com
 
Ad

Advertisements

S

Steve Rindsberg

Hi,

In Powerpoint 2003 I want to have a button on one of the toolbars that
places a box on the page.
I want the box to have:
- white fill
- black text
- Arial-Normal
- 12pt
- 2 lines of text (using a soft return to get to the second line)
- outline of the box 2 pt, black
- Order position on top of everything else
- Size of the box should be just large enough to accommadate the known text
that will go in the box.
- position of the text should probably just go in the center of the page and
then the user will move the box to where needed on the page. - but it would
be cool if there is a trick that allows positioning after pushing the
toolbar button.

I don't understand VBA but I can sort of induce a few things from looking at
the code that is generated when I record a macro of this:

Sub DPN_textbox2()
'
' Macro recorded 1/31/2005 by sk
'


I don't think you want the following two lines, so I'd lose them:
ActivePresentation.SlideMaster.TextStyles.Item(Type:=ppDefaultStyle).Levels(
Level:=1).ParagraphFormat.Alignment = ppAlignLeft

ActivePresentation.SlideMaster.TextStyles.Item(Type:=ppDefaultStyle).Levels(
Level:=1).Font.Name = "Arial"

Working with the selection is a bit clumsy at times, and won't work when you're
in slide show mode, but let's not worry about that for now:
ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizo
ntal, 264, 264, 78, 21.625).Select
ActiveWindow.Selection.ShapeRange.TextFrame.WordWrap = msoTrue
With ActiveWindow.Selection.TextRange.ParagraphFormat
.LineRuleWithin = msoTrue
.SpaceWithin = 1
.LineRuleBefore = msoTrue
.SpaceBefore = 0.5
.LineRuleAfter = msoTrue
.SpaceAfter = 0
End With
With ActiveWindow.Selection.ShapeRange
.Fill.ForeColor.SchemeColor = ppBackground
.Fill.Visible = msoTrue
.Fill.Solid
End With
With ActiveWindow.Selection.ShapeRange
.Line.Weight = 2.0
.Line.Visible = msoTrue
.Line.Style = msoLineSingle
End With
With ActiveWindow.Selection.ShapeRange
.Line.ForeColor.SchemeColor = ppForeground
.Line.Visible = msoTrue
End With

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1,
Length:=0).Select
With ActiveWindow.Selection.TextRange
.Text = "DPN yyyyyy" + Chr$(CharCode:=11) + "QTY= X"
With .Font
.Name = "Arial"
.Size = 12
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.SchemeColor = ppForeground
End With
End With
With ActiveWindow.Selection.ShapeRange
.ScaleWidth 1.23, msoFalse, msoScaleFromTopLeft
.ScaleHeight 0.91, msoFalse, msoScaleFromTopLeft
End With
ActiveWindow.Selection.ShapeRange.ScaleWidth 0.94, msoFalse,
msoScaleFromTopLeft
ActiveWindow.Selection.ShapeRange.ScaleWidth 0.93, msoFalse,
msoScaleFromTopLeft

You've just added the shape; it'll be on top already so skip this:
ActiveWindow.Selection.ShapeRange.ZOrder msoBringToFront

And there's no need to select it again, so lose this:
ActiveWindow.Selection.SlideRange.Shapes("Text Box 9").Select

And these:
 

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