VBA for Embedded Textbox: Changing margins

MacGyver7640

Board Regular
Joined
Oct 28, 2011
Messages
76
Hi simple problem,

So I have this code for creating a text box in a chart, based on the values in a cell. But it doesn't seem to be making the changes to the margins I want (they come out as 0.0).

Does anyone know what the problem is with my code for the margins?

Thanks so much!

Code:
Sub AddATextbox()

With ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 190.75, 29, 57.75, 35)
    .Name = "Event3"
    .TextFrame.Characters.Text = Sheets("Sheet2").Range("F18")
    .TextFrame2.AutoSize = msoAutoSizeShapeToFitText
    .TextFrame2.MarginBottom = 0.1
    .TextFrame2.MarginLeft = 0.1
    .TextFrame2.MarginRight = 0.1
    .TextFrame2.MarginTop = 0.1
    .TextFrame.Characters.Font.Name = "Times New Roman"
    .TextFrame.Characters.Font.Bold = True
    .TextFrame.Characters.Font.Size = 6
    'What does this do? compared to alignment below?
    .TextEffect.Alignment = msoTextEffectAlignmentCentered

End With

'Selects the newly created textbox "Event3" and places it towards the right
ActiveChart.Shapes("Event3").Select

With Selection
    .ShapeRange.Line.Weight = 0.75
    .ShapeRange.Line.DashStyle = msoLineSolid
    .ShapeRange.Line.Style = msoLineSingle
    .VerticalAlignment = xlCenter
'Not sure what these codes do...copied this section from another. Save for future textbox. 
'What does # do?
'   .HorizontalAlignment = xlCenter
'   .ShapeRange.Height = 10#
'   .ShapeRange.Width = 45#

End With
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Code:
    [COLOR="Red"].TextFrame.AutoMargins = False[/COLOR]
    .TextFrame.MarginBottom = [COLOR="Red"]Application.InchesToPoints(0.1)[/COLOR]
    .TextFrame.MarginLeft = [COLOR="Red"]Application.InchesToPoints(0.1)[/COLOR]
    .TextFrame.MarginRight = [COLOR="Red"]Application.InchesToPoints(0.1)[/COLOR]
    .TextFrame.MarginTop = [COLOR="Red"]Application.InchesToPoints(0.1)[/COLOR]
 
Upvote 0
Code:
    [COLOR="Red"].TextFrame.AutoMargins = False[/COLOR]
    .TextFrame.MarginBottom = [COLOR="Red"]Application.InchesToPoints(0.1)[/COLOR]
    .TextFrame.MarginLeft = [COLOR="Red"]Application.InchesToPoints(0.1)[/COLOR]
    .TextFrame.MarginRight = [COLOR="Red"]Application.InchesToPoints(0.1)[/COLOR]
    .TextFrame.MarginTop = [COLOR="Red"]Application.InchesToPoints(0.1)[/COLOR]

Error on the first line: Method or data member not found :(

Found a reference to this problem here. Apparently automargins doesn't work in 2007?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,528
Messages
6,125,342
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top