Paste to Toolbar Textbox

B

Benz

Hi,

I have a toolbar with a textbox - im trying to create a macro that will copy
the selected text and auto paste to the textbox in the toolbar.

This is what I thought would work but isint.....

Any help would be appreciated.

Sub Ldtaskbr()
'To paste selected text in 'Task' Toolbar

Dim sendList As CommandBarComboBox ' list of users (Textbox) (2)'

Set sendBar = Application.CommandBars("Task")
Set sendList2 = sendBar.Controls.Add(Type:=msoControlEdit, Before:=1)

Selection.Copy

With sendList2
.Text = Slection.Paste
End With

End Sub
 
H

Helmut Weber

Hi Benz,

it must have been more than an hour
to find out whats wrong.

You have to define the control you add as msoControlComboBox.

No:
Controls.Add(Type:=msoControlEdit, Before:=1)
Yes:
Controls.Add(Type:=msoControlComboBox, Before:=1)

Otherwise you can set its text, but the additem-method fails.
Though setting the text of a combobox works,
it is entirely useless, as there would be
no different items to choose from.

' -------------------------------------------
Sub Ldtaskbr()
Dim sendbar As CommandBar
Dim sendbox As CommandBarComboBox
Set sendbar = Application.CommandBars("Custom01")
Set sendbox = sendbar.Controls.Add(Type:=msoControlComboBox, _
Before:=1)
End Sub

' -------------------------------------------

Sub test1()
Dim sendbar As CommandBar
Dim sendbox As CommandBarComboBox
Set sendbar = Application.CommandBars("Custom01")
Set sendbox = sendbar.Controls(1)
With sendbox
.AddItem Selection.Text
End With
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
B

Benz

Thank you! I apprecaite the help. It's a textbox so there won't be any drop
down items. But im still not able to paste the selection to the textbox ,
what can I put in the place of 'add' to it has the right target?

Controls.Add(Type:=msoControlComboBox, Before:=1)


Thank you,

Ben Z.
 
H

Helmut Weber

Hi Benz,

if it has to be, wondering why,

Sub Ldtaskbr()
Dim sendbar As CommandBar
Dim sendbox As CommandBarControl
Set sendbar = Application.CommandBars("Custom01")
Set sendbox = sendbar.Controls.Add(Type:=msoControlEdit, _
Before:=1)
End Sub

' -----------------------------------------------
Sub test1()

Dim sendbar As CommandBar
Dim sendbox As CommandBarControl
Set sendbar = Application.CommandBars("Custom01")
Set sendbox = sendbar.Controls(1)
With sendbox
.Text = Selection.Text
End With
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top