Accessing the clipboard from Visio

Started by DC Kelley, June 19, 2011, 11:00:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DC Kelley

Subtle differences in the VB vs VBA object model seem to be thwarting me today.  I just want to get to the clip board and put some text up on it (and perhaps latter a shape object) but can set to get a suitable object.  How does this work in Visio???

In a full up VB environment this is rather simple, just two lines:
Clipboard.Clear
Clipboard.setText ("foo")


From what I can tell the below is the preferred method for Visio, but my VBA can not find the object DataObject and therefore will not run.

    Dim oData As DataObject ' Allocate DataObject to access the clipboard
    Set oData = New DataObject ' create one
    oData.GetFromClipboard ' Get data from clipboard into dObj
    oData.PutInClipboard "foo" ' paste text to clipboard


The only use of this method I find on the board will not run for the same reason.
What does one have to do in order to use the DataObject object?

Jumpy

Hi DC,
as I recall, DataObject is not part of the Visio Object Model. Therefore you need to set the reference to the right library in the VBA-Editor. At a guess I would say to:

Microsoft Forms 2.0 Object Library

or

Microsoft DataList Controls ...

DC Kelley

Quote from: Jumpy on June 20, 2011, 06:28:35 AM
Hi DC,
as I recall, DataObject is not part of the Visio Object Model. Therefore you need to set the reference to the right library in the VBA-Editor. At a guess I would say to:
Microsoft Forms 2.0 Object Library
or
Microsoft DataList Controls ...

Hummm.... I do not see either of these listed in the choices in either this VBA project (using VB 6.5 released in 2006) or in a larger older "pre-net classic" VB6 project I am grabbing prior code from. 

A quick look at VB 2005 (where you can finally see the details of each registered dll) under the COM tab and I see Datalist (SP3) and a coupe copies of the Forms dll.    Perhaps a slightly different name would be used on older Visio copies?   I had to revert to the 2001 release when my 2003 copy suddenly could not find the VBA environment anymore (another things yet to resolve).  Clearly this object has existed for a long time as my old VB6 finds it with no problem.  This machine has most years from VB6 to Net 2005 on it so there are lots of choices to get lost in, but version issues are starting to become a constant problem.

I have added some of the other references from another VB6 project (where this object is exposed and used) but still no go. For reasons I can not explain, I can not add a ref to either Visual Basic runtime objects and procedures or to Visual Basic objects and procedures and am wondering if that is my issue or if this is perhaps another VB vs VBA thing, or a old-new VB editor thing.

DC Kelley

SOLVED  An update, the file for "Microsoft Forms 2.0 Object Library" is in fact called FM20.DLL and in my case it was sitting there in the normal place in /system32.  So now the ref work and the three lines below do the job. 

    Dim oData As New DataObject
    oData.SetText MyStringToPlaceOnCLipBd
    oData.PutInClipboard


I can not explain why each of my various VB installs all seem to have different collection of objects I can reference  I think the lesson learned is all get the real file name and grab it with the browser dialog.  Nor can I tell why the direct calls to the clipboard itself can not be used, oh well back to the next problem.  Thanks to Jumpy for the key to this.

A useful thread on using the user32 calls to solve this (and in case you need more then just text, this is what you must do) is at: http://www.cpearson.com/excel/Clipboard.aspx