PDA

View Full Version : Textbox Alignment and Stuff [Help]



ImprovingMys
01-16-2017, 03:01 AM
Hello there,

I am a VBA-Beginner and need some help with shapes and its formatting. I´ve been searching for a few hours on the internet but have not found anything which could help me.
I´d like to add several textboxes into my project with special alignment, fills and so on. This is what I have got so far:

Dim xLeft, xWidth, xHeight As Single

Set myDoc = Documents(1)

xLeft = 57.14
xWidth = 496
xHeight = 12


With myDoc.Shapes.AddTextbox(msoTextOrientationHorizontal, xLeft, 100, xWidth, xHeight)
.Fill.BackColor.RGB = RGB(177, 216, 216)
.Line.Visible = False
...
End with

For further steps I want to type a bold text (e.g. "Date: 16.01.2017") into the textbox with alignment to the right and the inner side egdes set to a minimum.

Can anyone help me and (to everybodys advantage) maybe recommend a website to me where I can find stuff like this?

Thanks a lot!

- Marco

gmaxey
01-16-2017, 08:31 AM
Not sure what the minimum margins are but following seems to work and will with text that has characters that extend below the baseline e.g., g, j, p etc.


Sub ScratchMacro()
Dim xLeft, xWidth, xHeight As Single
Dim oDoc As Document
Set oDoc = Documents(1)
xLeft = 57.14
xWidth = 496
xHeight = 12
With oDoc.Shapes.AddTextbox(msoTextOrientationHorizontal, xLeft, 100, xWidth, xHeight)
.Fill.BackColor.RGB = RGB(177, 216, 216)
.Line.Visible = False
With .TextFrame
.MarginBottom = 0.01
.MarginTop = 0.01
.MarginRight = 0.01
.MarginLeft = 0.01
With .TextRange
.Bold = True
.Font.Size = 10
.Text = "Date: " & Format(Now, "DD.MM.YYYY")
End With
End With
End With
End Sub