Results 1 to 9 of 9
  1. #1
    Lounger
    Join Date
    Apr 2002
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DataObject (VBA 5 and 6)

    I have been using this code at the end of some macros to clear my clipboard memory. I works fine for me in Word 97, 2000, and 2002.

    Dim MyData As DataObject
    Set MyData = New DataObject
    MyData.SetText ""
    MyData.PutInClipboard

    I have friends with the Word 2000 and 2002 who have not been able to use it. They get this message for first line: "compile error: user-defined type not defined" .

    Does any one know how to rewrite it so it will run?

    Thanks.

    Jerry

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: DataObject (VBA 5 and 6)

    Hi Jerry,
    Your friends need to set a reference to the Microsoft Forms object library for your code to work or else you can use Windows API functions instead:
    <pre>Private Declare Function GetActiveWindow Lib "user32" () As Long
    Private Declare Function CloseClipboard Lib "user32" () As Long
    Private Declare Function OpenClipboard Lib "user32" _
    (ByVal hwnd As Long) As Long
    Private Declare Function EmptyClipboard Lib "user32" () As Long
    Sub clearclippy()
    OpenClipboard GetActiveWindow
    EmptyClipboard
    CloseClipboard
    End Sub
    </pre>

    for example.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Lounger
    Join Date
    Apr 2002
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DataObject (VBA 5 and 6)

    Rory:

    Thanks. I'll try that. I guess what puzzles me is that we are all using the exact same modules.

    Jerry

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: DataObject (VBA 5 and 6)

    In Word 97 (and Excel 97), a reference to the Microsoft Forms 2.0 Object Library was set by default; in Word 2000 and 2002 this is not the case. Why? <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

  5. #5
    Lounger
    Join Date
    Apr 2002
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DataObject (VBA 5 and 6)

    Hans:

    Thanks. I got it now.

    Jerry

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DataObject (VBA 5 and 6)

    The reference gets set when one inserts a Userform.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: DataObject (VBA 5 and 6)

    Yes, but the DataObject is useful even if you have no UserForms. In Word 97, you didn't have to worry about using DataObject because the reference to MS Forms 2.0 was ALWAYS set. In Word 2000/2002, you must set the reference, either explicitly, or - as you indicate - implicitly by inserting a UserForm.

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: DataObject (VBA 5 and 6)

    > we are all using the exact same modules

    If they imported them into their own project, that could explain the discrepancy. I believe references are stored at the project level and aren't in the .bas files.

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DataObject (VBA 5 and 6)

    I hate to defend MSFT, but MSFT was correct in requiring an explicit reference to be entered.
    Automatically including references can lead to problems.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •