Using a Text Box in Excel Visual Basic

  Desert Andy 13:35 11 Feb 05

I am trying to put a small text box in a graph using vb. My problem is that using the code Selection.Characters Text="Anything", i can't enter a variable as opposed to the text "Anything". Anyway I can do this?

Thanks for the help

  VoG II 13:41 11 Feb 05

Sub tst()

Dim txt As String

txt = "VoG Example"

ActiveSheet.Shapes("Text Box 1").Select

Selection.Characters.Text = txt

End Sub

  Desert Andy 14:15 11 Feb 05

It won't take the variable for some reason?

  VoG II 14:18 11 Feb 05

I've tested the above code on both a worksheet and a chart sheet and it works for me (Excel 2003).

  Desert Andy 14:23 11 Feb 05

OK, how did you add the text box in the first place with the name "Text Box 1".

Its driving me nuts

  VoG II 14:24 11 Feb 05

I've mailed you. The name should appear in the Name Box if you select the text box by clicking on it.

  VoG II 14:28 11 Feb 05

[URL=click here][IMG]click here[/IMG][/URL]

  Desert Andy 14:39 11 Feb 05

ok,the code I have written is as follow

ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 302.25, 93.75, _
78.75, 30#).Select
Selection.Characters.Text = CourseSelectionGradMissions(ILoop)

However, it gives an error code.

Any thoughts

  VoG II 14:45 11 Feb 05

This works

Sub tst()

Dim txt As String

txt = "another example"

ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 81#, 39.75, 115.5, 48#).Select

Selection.Characters.Text = txt

End Sub

so I think the problem lies in what is in CourseSelectionGradMissions(ILoop)

  Desert Andy 15:19 11 Feb 05

ok, i have tried this code elsewhere in the workbook, and as you say it works fine. But put it an the end of my current code, and it fails every time.
I haven't got any hair left!

  VoG II 15:29 11 Feb 05

What is the error message?

This thread is now locked and can not be replied to.

Nintendo Switch (Nintendo NX) release date, price, specs and preview trailer: Codename NX console…

1995-2015: How technology has changed the world in 20 years

8 things designers (and brands) need to know about the modern woman

How to speed up a slow Mac: 19 great tips to make an iMac, MacBook or Mac mini run faster | Speed…