Using a Text Box in Excel Visual Basic

  Desert Andy 13:35 11 Feb 2005
Locked

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 2005

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 2005

It won't take the variable for some reason?

  VoG II 14:18 11 Feb 2005

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 2005

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 2005

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 2005

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

  Desert Andy 14:39 11 Feb 2005

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 2005

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 2005

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 2005

What is the error message?

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

Elsewhere on IDG sites

AMD Radeon Adrenalin release date, new features, compatible graphics cards

Inside the iMac Pro - Apple's most powerful Mac yet

iMac Pro release date, UK price & specs

Comment nettoyer Windows et optimiser son PC gratuitement ?