LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ActiveX and characters textbox

I am using Labview 7.0 and want to insert text into a text box in Microsoft Excel using ActiveX. The textbox is a shape object in excel. I can get to the select object, but can't seem to find an option for Characters, text or an edit text function. The VB code to perform the task is as follows.
ActiveSheet.Shapes("txtComments").Select
Selection.Characters.Text = ""
Selection.Characters.Text = "" & Chr(10) & "" & Chr(10) & "Insert this text into box" & Chr(10) & ""
'use vbCrlf for line feed/return
0 Kudos
Message 1 of 4
(3,320 Views)
When using ActiveX to control Excel, you frequently need to typecast a reference from the generic list of possibilities into the specific item that you know is being referenced. This is almost always the case with the Selection or Item methods.

Use the Variant to Data.vi to typecast the reference to the known reference type. You will need to place a reference constant of the known type on the front panel to accomplish this. I included a screenshot of the following VB where the indexed shape is known to be a textbox:

Shapes(1).Text = Text

Michael Munroe
Certified LabVIEW Developer
www.abcdef.biz
Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.1, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
Message 2 of 4
(3,321 Views)
I am trying to do the same thing.  When using your example, I get an error from the Variant to Data function.  For the type constant, I tried browsing to all kinds of MS textbox objects (from 2 excel versions, 2 office objects versions, forms, textframe2.textrange.text, anything I could find.  I am not familiar with VB.  The properties Type and Name both return values identifying the only textbox in the worksheet.

The pictured type constant (feeding the variant to data function) is from either
Microsoft Excel 11.0 Object Library Version 1.5
Microsoft Excel 5.0 Object Library Version 1.0

Any help would be appreciated.

0 Kudos
Message 3 of 4
(3,122 Views)
Figured it out, see picture.

If your text is greater than 255 characters, you will have to split it and set the Start input on the TextFrame property node to the correct offset to append to what is already there.  Otherwise it does not put the text in the textbox, but does NOT return any error.
0 Kudos
Message 4 of 4
(3,091 Views)