Clipboard Problem using VBA

Discussion in 'Word Programming' started by h.simonot@gmail.com, Apr 6, 2012.

  1. Guest

    Hi everybody,

    I've a stange behavior in my macro (Windows XP SP3, Office 2002 SP3) :

    I try to copy and paste some text from a word document to another (from an excel VBA project).

    I use this kind of code :
    doc1.ActiveDocument.Content.Copy
    ....
    doc2.Selection.Paste

    It works most of the time...

    But with some computers, instead of copying doc1 to doc2... It just paste a bitmap icon in doc2. I don't even know where does it come from !

    Has somenone an idea ? I'm completely lost !
    The most strange : if I put a break point after doc1.ActiveDocument.Content.Copy, and try to paste in another document, it works ! VBA Memory leak ?

    Thanks a lot.
     
    , Apr 6, 2012
    #1
    1. Advertisements

  2. Auric__ Guest

    "h.simonot" wrote:

    > I've a stange behavior in my macro (Windows XP SP3, Office 2002 SP3) :
    >
    > I try to copy and paste some text from a word document to another (from
    > an excel VBA project).
    >
    > I use this kind of code :
    > doc1.ActiveDocument.Content.Copy
    > ...
    > doc2.Selection.Paste
    >
    > It works most of the time...
    >
    > But with some computers, instead of copying doc1 to doc2... It just
    > paste a bitmap icon in doc2. I don't even know where does it come from !
    >
    > Has somenone an idea ? I'm completely lost !
    > The most strange : if I put a break point after
    > doc1.ActiveDocument.Content.Copy, and try to paste in another document,
    > it works ! VBA Memory leak ?


    You could try clearing the clipboard before your code:

    Declare Function CloseClipboard Lib "user32" () As Long
    Declare Function EmptyClipboard Lib "user32" () As Long
    Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long

    Sub foo()
    OpenClipboard 0
    EmptyClipboard
    CloseClipboard
    doc1.ActiveDocument.Content.Copy
    '...
    doc2.Selection.Paste
    End Sub

    Don't know if that would solve your problem, though.

    --
    Remember, you may have to grow old, but you don't have to mature.
     
    Auric__, Apr 7, 2012
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Copy to clipboard

    , Feb 10, 2005, in forum: Word Programming
    Replies:
    2
    Views:
    129
  2. braz

    Copy-paste office documents via clipboard

    braz, Mar 22, 2007, in forum: Word Programming
    Replies:
    1
    Views:
    320
    JensB
    Mar 30, 2007
  3. nitm

    encoding problems with clipboard.getdata

    nitm, Jul 29, 2007, in forum: Word Programming
    Replies:
    0
    Views:
    107
  4. Bob

    Word clipboard with VB 2005

    Bob, Aug 15, 2007, in forum: Word Programming
    Replies:
    0
    Views:
    100
  5. Macro''''er

    Copy certain text to Clipboard macro

    Macro''''er, Feb 13, 2009, in forum: Word Programming
    Replies:
    3
    Views:
    112
    Jay Freedman
    Feb 17, 2009
  6. Macro''''er

    Put certain text to clipboard macro

    Macro''''er, Feb 13, 2009, in forum: Word Programming
    Replies:
    0
    Views:
    134
    Macro''''er
    Feb 13, 2009
  7. Macro''''er

    macro to put certain text to clipboard

    Macro''''er, Feb 17, 2009, in forum: Word Programming
    Replies:
    1
    Views:
    119
    Doug Robbins - Word MVP
    Feb 17, 2009
  8. Perky

    clipboard size

    Perky, Apr 28, 2009, in forum: Word Programming
    Replies:
    0
    Views:
    124
    Perky
    Apr 28, 2009
Loading...