Question

Dear VB enthusiasts with Office-Automation experience,

Context: I am trying to develop a Ribbon Add-In for Office Powerpoint using VB.Net in Visual Studio 2010.

Problem: I am trying to add a watermark with dynamic and transparent text to all Powerpoint 'Objects' on each slide, and then convert them to an image - but I can't make the text transparent.

The task appears simple, but I tried multiple times before I considered consulting!

Current Attempt: Say I code the following to receive a basic text-based watermark above a given object:

NewPresentation.Slides(Slide).Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, Left, Top, Width, Height)

With NewPresentation.Slides(Slide).Shapes(NewPresentation.Slides(Slide).Shapes.Count)

    .TextFrame.TextRange.Text = WatermarkText
    .Line.Visible = MsoTriState.msoFalse

    .Width = Math.Sqrt((Object.Width * Object.Width) + (Object.Height) * Object.Height))
    .Rotation = -(Math.Atan(Object.Height) / (Object.Width) * (180 / System.Math.PI)) ' - Angle * Radius->Degree ratio (Atan returns radius)

    .Left = (Object.Left + (Object.Width / 2)) - (.Width / 2)
    .Top = (Object.Top + (Object.Height) / 2)) - (.Height / 2)

    .Name = "Watermark_" & Group

End With

The above inserts a new TextBox, sets the text, hides the lines, sets the width (based on object size), rotates the textbox (based on objects width/height ratio), sets the left and right positions (based on object position), and names the shape.

Now all I need to do is select the Text-Box and it's Object, Copy them, Delete them, Paste both as an Image and re-position the image shape - Success!

This ALL works perfectly.

However, what if I want the text to be transparent?

I know of three possible methods to achieve this:

1 - You can Format Text Effects of TextBox's Text to make it transparent (Manually)

2 - You can copy a TextBox, create a new shape and set its background from the clipboard, and change the fill transparency (Manually)

3 - You can copy a TextBox, Paste as Image, Save the Image, Create a new Shape and set the Background from file, and change the fill transparency (Manually).

I can't create a pre-made image because the Watermark text needs to be dynamic.

I have tried all three, and failed at one particular stage of each;

(1) I don't know how to set the Text-Fill Format for a TextBox's Text to make it transparent

(2) I don't know how to set a shapes background from the clipboard

(3) I don't know how to save a shape as an image

Would someone be able to show me how to do one of the above, or maybe provide a more suitable suggestion?

I would be happy to expand or re-structure this question or provide more code samples upon request.

Best Regards

Was it helpful?

Solution

Example to set the selected text to 50% transparent green:

Dim oRng As TextRange2
Set oRng = ActiveWindow.Selection.TextRange2

With oRng
    .Font.Fill.ForeColor.RGB = RGB(0, 255, 0)
    .Font.Fill.Transparency = 0.5    
End With

Note that we work with TextRange2 rather than TextRange (TextRange2 exposes some new properties introduced in versions of PPT after 2003, transparency being one of them).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top