I added the textbox going through the Textboxes collection--not through the
shapes collection.
Option Explicit
Sub testme()
Dim DealTextBox As TextBox
Dim y As Long
Set DealTextBox = ActiveSheet.TextBoxes.Add _
(Top:=0, Left:=0, Width:=300, Height:=200)
With DealTextBox
.AutoSize = True
If .Width 300 Then
y = .Width * .Height
.Width = 300
.Height = (y / 200)
End If
.Formula = "=Sheet1!a1"
.Characters(1, 11).Font.Bold = True
End With
End Sub
But if you point to a cell, I don't think bolding of characters will work the
way you want.
wrote:
Good afternoon!
I have a macro which creates text boxes in excel, based on values in a
hidden worksheet. One of thos values is a location within the
workbook, ie "Sheet1!A2". When creating the textbox in vba, I would
like the text box (or the text within the box) to be linked to that
cell. I have looked everywhere and cannot find anything on how to do
this.
Here is the code which creates the textbox:
dim dealtextbox as shape
Set DealTextbox =
Sheets(1).Shapes.AddTextbox(Orientation:=msoTextOr ientationHorizontal,
_
Left:=350, Top:=lengthPrevBox + 10, Width:=600, Height:=10)
With DealTextbox
.TextFrame.AutoSize = True
If .Width 300 Then
y = .Width * .Height
.Width = 300
.Height = (y / 200)
End If
.TextFrame.Characters(1, 11).Font.Bold = True
end with
--
Dave Peterson