Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clipboard (Office XP) 2

Status
Not open for further replies.

565u

Technical User
Apr 25, 2005
46
CZ
Hi and thanks for reading my question!
I use .CopyFace/.PasteFace in one of my codes and they take advantage of Clipboard, which is a problem for me, because the clipboard may contain data (usualy text). I think I can either choose another method to replace Copy/PasteFace or store the clipboard content safely first. basically I think I need to figure out how to work with Clipboard, but I find the help in Office XP difficult to uderstand for me and the web contains mostly advice for newer VB. Could somebody kindly point me in the right direction? Below is the Office Help text I suspect holds the answer but I just cannot get it to run. Every time I try to use "Dim MyData as DataObject", it I get "Compile error: User-defined type not defined". I am doing something wrong but I dont know what.

Any help, please?

Best regards,

Pavel


---- help from office xp ----

Copy, GetFromClipboard, GetText Methods, DataObject Object Example
The following example demonstrates data movement from a TextBox to the Clipboard, from the Clipboard to a DataObject, and from a DataObject into another TextBox. The GetFromClipboard method transfers the data from the Clipboard to a DataObject. The Copy and GetText methods are also used.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

Two TextBox controls named TextBox1 and TextBox2.


A CommandButton named CommandButton1.
Dim MyData as DataObject

Private Sub CommandButton1_Click()
'Need to select text before copying it to Clipboard
TextBox1.SelStart = 0
TextBox1.SelLength = TextBox1.TextLength
TextBox1.Copy

MyData.GetFromClipboard
TextBox2.Text = MyData.GetText(1)
End Sub

Private Sub UserForm_Initialize()
Set MyData = New DataObject
TextBox1.Text = "Move this data to the " _
& "Clipboard, to a DataObject, then to "
& "TextBox2!"
End Sub
 
HI,

You might need to set a reference to the MSForms library.

Tools > References

...and scroll to that reference.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thank you very much for your kind answer, SkipVought! It seems to be working. If you or anybody else could kindly guide me a bit further, it would be very nice too. Right now I am trying to get the text from the clipboard into a variable (xText), but Word does not like what i do to it (see below). I've never done anything with clipboard before, probably doing something very stupid now...


Dim MyData As DataObject
Dim xText As String
MyData.GetFromClipboard ' produces this error: "Object variable or With block variable not set"
xText = MyData.GetText(1)
MsgBox xText



Best regards,

Pavel
 
Set MyData = New DataObject

...before using MyData

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
If .CopyFace/.PasteFace is used only for copying images between two commandbar buttons, you can alternatively use direct assignment:
[tt]cbb_2.Picture = cbb_1.Picture
cbb_2.Mask = cbb_1.Mask[/tt]


combo
 
@SkipVought
Thank you very much again!!

@combo
Very good idea! Thank you!

Best regards!
:)
Pavel
 
@combo:
could you be so kind and give me more details, please?
 
i take it back, just solved it
for those who need it:
CommandBars("toolbarname").Controls(1).Picture = CommandBars("toolbarname").Controls(2).Picture

:)
Pavel
 
and a little tip: you can use button names instead of their numbers
e.g. CommandBars("toolbarname").Controls("thebigbutton").Picture = CommandBars("toolbarname").Controls("thebiggerbutton").Picture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top