Add textbox to slide

G

Gil

Hello,

I use the folowing Sub to add a TextBox to the last slide of my ppt,

Sub GetOLETextBoxRef()
Dim shp As Shape
Dim txtBox As TextBox
Dim lastSlideNumber As Integer

lastSlideNumber = ActivePresentation.Slides.Count

' Set a reference to the added shape
Set shp = ActivePresentation.Slides(lastSlideNumber).Shapes. _
AddOLEObject(174#, 222#, 175#, 25#, _
ClassName:="Forms.TextBox.1")
'Now get the object reference from the shape reference
Set txtBox = shp.OLEFormat.Object
' Format properties of the textbox as required.
With txtBox

.Text = "This is the best NG"

End With
End Sub

I want to change textBox properties like: fill, color, hyperlink etc.
I added the folowing code before the last 'End with' but I get error.

.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(153, 204, 255)
.Fill.Transparency = 0#
.Line.Visible = msoTrue
.Line.ForeColor.SchemeColor = ppForeground
.Line.BackColor.RGB = RGB(255, 255, 255)

How can I modify my textBox properties ?

Thank you
Gil D.
 
C

Chirag

You can perhaps write an OnClick event handler for the textbox OLE control
and use ShellExecute() WinApi to launch the hyperlink as follows:

---
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Sub PrintPDFFile()
ShellExecute 0, "open", http://www.microsoft.com, "", "", 1
End Sub
---

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
B

Bill Dilworth

Hi Gil,

Just out of curiosity, why do you need an ActiveX text box instead of a
regular one? It seems like to are using it in a static form, rather than
the dynamics offered by the ActiveX ones.

If you change the type of text box, it becomes a bit easier to utilize and
insert a hyperlink.

What you are doing isn't wrong, just seemingly harder than it needs to be.


--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.
http://billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
vestprog2@ Please read the PowerPoint FAQ pages.
yahoo. They answer most of our questions.
com www.pptfaq.com
..
 
G

Gil

Hi Bill,

I am new to powerpoint VBA.
I found this ActiveX text box example in microsoft.public.powerpoint.

I did not find an example of regular textbox.

Can you tell me where can I find VBA code for this ?

Thank you
Gil D.
 
G

Gil

Hi Chirag,

Thank you for your help.
I think that using a regular TextBox will be easier for me (as Bill
said).

Thank you
Gil D.
 
B

Bill Dilworth

This should get you within plug-n-play range ....


-------begin code---------

Sub AddRegularTextBox()

Dim lastSlideNumber As Integer
lastSlideNumber = ActivePresentation.Slides.Count

With ActivePresentation.Slides(lastSlideNumber) _
.Shapes.AddTextbox _
(msoTextOrientationHorizontal, _
174, 222, 300, 100)

.TextFrame.AutoSize = ppAutoSizeNone
.TextFrame.VerticalAnchor = msoAnchorMiddle

With .TextFrame.TextRange
.Text = "Yes, it is"
.ActionSettings(ppMouseClick).Hyperlink _
.Address = "http:\\www.pptfaq.com"
' Note the hyperlink color will override this
.Font.Color.RGB = RGB(255, 0, 0)
.Font.Shadow = msoTrue
.ParagraphFormat.Alignment = ppAlignCenter
.Font.Size = 45
End With

With .Line
.ForeColor.RGB = vbBlue
.Transparency = 0
.Visible = msoTrue
End With

With .Fill
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0.5
.OneColorGradient msoGradientDiagonalUp, 4, 1
End With

End With

End Sub

-------end code---------


--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.
http://billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
vestprog2@ Please read the PowerPoint FAQ pages.
yahoo. They answer most of our questions.
com www.pptfaq.com
..
 
G

Gil

Hi Bill,

Thank you very much. Is solved my problem.

I have another queastion:
I have a slide named "main report" in which there are some Rectangle
with hyperlinks.

How can I choose this slide by name using VBA in order to update
links ?

I tried the following code but it did not work:

Sub GoToNamedSlide()
ActivePresentation.SlideShowWindow.View.GotoSlide _
ActivePresentation.Slides("main report").SlideIndex
End Sub

Thank you
GIl
 
G

Gil

Hi Bill,

Thank you very much. You solved my problem.

I have another queastion:
I have a slide named "main report" in which there are some Rectangle
with hyperlinks.

How can I choose this slide by name using VBA in order to update
links ?

I tried the following code but it did not work:

Sub GoToNamedSlide()
ActivePresentation.SlideShowWindow.View.GotoSlide _
ActivePresentation.Slides("main report").SlideIndex
End Sub

Thank you
GIl
 
D

David M. Marcovitz

Gil,

I think you are confusing the slide name with the slide title. The title
of the slide is the one you type in the title area. The name of the slide
is set in different way. Look at Example 8.7 on my site
(http://www.PowerfulPowerPoint.com/) for procedures to name shapes and
slides. Then, once you name the slide, your code below will work.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
G

Gil

Hi David,

Thank you very much for your help.
You are right - I confused the slide title with the slide name.
I understood how it works and how can I modify and use it from your
code example.

Thank you
Gil D.
 

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