Insert Text Box

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,059
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this code, and is working all fine, but I am not sure as how to add more text box, I mean the code should add 30 text box.
Currently it is adding on 1 textbox. Any idea.

VBA Code:
Sub DrawTextbox()
    Dim ws As Worksheet, s As Shape
    Set ws = ActiveSheet
    ActiveWindow.SmallScroll up:=26
    ActiveWindow.SmallScroll Down:=26
    
    ' Create label (height/width will be set by AutoSize).
    Set s = ws.Shapes.AddShape(msoShapeRectangularCallout, 12.5, 723.75, 80, 46.25)
    's.IncrementRotation 180
    s.Adjustments.Item(1) = -0.46355
    s.Adjustments.Item(2) = -1.39427
    s.TextFrame.Characters.Text = Sheets("Tables").Range("c5") '"This is some label text"
   ' s.TextFrame.AutoSize = True
    
    With s.TextFrame2.TextRange.Font.Fill
         .ForeColor.RGB = RGB(0, 0, 0)
    End With
  
   s.Select
    With Selection.ShapeRange.Line
        .Visible = msoTrue
        .Weight = 0.75
        .Transparency = 0
        .ForeColor.RGB = RGB(0, 0, 0)
    End With
    
    Selection.ShapeRange.Fill.Visible = msoFalse



'    With Selection.ShapeRange.Line
'        .Visible = msoTrue
'        .ForeColor.RGB = RGB(0, 0, 0)
'        .Transparency = 0
'    End With
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Code:
For i=1 to 10
' macro from 'create lable
'somewhere in the middle
s.Name="MySpeechOutNumber"&i
' before End Sub
Next i
 
Upvote 0
cool. done.
working fine.

If i want to give the condition , like if the cells are blank then don't create a text box, but if the cell value is not blank then create the text box with that value.
 
Upvote 0
so instead of
Code:
For i=...
Next i
you can do something like:
Code:
dim cell as Range
for each cell in range("C1:C10")  'as I see text inside object is from col. C
  if cell.value<>"" then
     ' you main part of macro which create object
 end if
next cell
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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