• DataObject (VBA 5 and 6)

    Author
    Topic
    #387798

    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

    Viewing 0 reply threads
    Author
    Replies
    • #678260

      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:

      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
      

      for example.
      Hope that helps.

      • #678299

        Rory:

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

        Jerry

        • #678323

          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? shrug

          • #678355

            Hans:

            Thanks. I got it now.

            Jerry

          • #678363

            The reference gets set when one inserts a Userform.

            • #678382

              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.

            • #678526

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

        • #678455

          > 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.

    Viewing 0 reply threads
    Reply To: DataObject (VBA 5 and 6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: