Fill worksheet textbox from vba

Martin1962

New Member
Joined
Mar 17, 2014
Messages
10
Hi,

I have a worksheets called "Sheet1" with multiple embedded textboxes.
in a second worksheet ("Sheet2" I keep my data)

In my code I create 'Public objSheetIn, objShootOut as worksheet'
In the section "Workbook_open" I have this :

DIm shp as Shape

Set objSheetIn = Worksheets("Sheet1")
Set objSheetOut = Worksheets("Sheet2")

I check if the worksheet contains Shapes (If objSheetIn.Shapes.Count > 0 then ...)

Then I run through all shapes :

For Each shp In objSheetIn.Shapes
If Left(shp.Name, 4) = "Txt_" Then

the next instruction goes wrong (assign some text)

objSheetIn.Shapes(shp.Name).TextFrame.Characters.Text = objSheetOut.Cells(1,1)

This retuns error 438 : Object doesn't support this property or method.

Can someone please indicate what's going wrong ?

Kind regards,

Martin
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Are the textboxes ActiveX or Form controls?
 
Upvote 0
Hi Fluff,

They are just Form controls.
When I go into Design Mode, they all are referenced as "=EMBED("Forms.TextBox.1","")", with each a name that starts with "Txt_"

Regards,

Martin,
 
Upvote 0
In that case they are ActiveX controls, not form controls.
Try
VBA Code:
   Dim Obj As Variant
   For Each Obj In objSheetIn.OLEObjects
      If Obj.Name Like "Txt_*" Then
         Obj.Object.Text = objSheetOut.Cells(1, 2)
      End If
   Next Obj
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0
I hope I'm allowed to add this question :

Onces all 40 activeX Textboxes are 'loaded', how do I position the cursor in Textbox "Txt_date" , as if I click on it ?

Regards,

Martin.
 
Upvote 0
How about
VBA Code:
objSheetIn.Txt_Date.Activate
Obviously the sheet will need to be the active sheet
 
Upvote 0
Hi Fluff,

That was my initial idea :

objSheetIn.Activate
objSheetIn.Txt_date.Activate

But i'm getting a compiler error on the last line:
Method or data member not found

Even replacing Txt_date by the name of another (exisiting) textbox, like Txt_name is giving the same result/error.

Regards,

Martin
 
Upvote 0
ok, try it like
VBA Code:
   objSheetIn.OLEObjects("Txt_date").Activate
 
Upvote 0

Forum statistics

Threads
1,215,356
Messages
6,124,471
Members
449,163
Latest member
kshealy

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