Results 1 to 6 of 6

Thread: PutInClipboard Office 365

  1. #1
    Board Regular gallen's Avatar
    Join Date
    Jun 2011
    Location
    Manchester UK
    Posts
    1,896
    Post Thanks / Like
    Mentioned
    21 Post(s)
    Tagged
    1 Thread(s)

    Default PutInClipboard Office 365

    My company has just upgraded to 365.

    My previous version was Office 2013

    I had code that copied the text from a selected cell to the clipboard. This now doesn't work in 365

    The code is as below:

    Code:
    Public Sub AddToClipboard(s As String)
       
    Dim oCopy As DataObject
    
    
            Set oCopy = New DataObject
            oCopy.SetText s
            oCopy.PutInClipboard
        
    End Sub
    This has worked fine until 365 was installed.

    I tried late binding using similar code I found from Google:

    Code:
    Sub CopyText(Text As String)
        Dim o As Object
        Set o = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
        o.SetText Text
        o.PutInClipboard
        Set o = Nothing
    End Sub
    This has the same result. When I paste anything I've copied it shows "??"

    I've debugged line by line and the correct text is being added in the 'SetText' line but pasting gives me the 2 question marks.

    Any clues?

    - forum use guidelines, forum rules and terms of use

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


  2. #2
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,970
    Post Thanks / Like
    Mentioned
    52 Post(s)
    Tagged
    6 Thread(s)

    Default Re: PutInClipboard Office 365

    It's actually nothing to do with Office. There's a bug in Windows 8 and later that causes this to happen if you have File Explorer windows open. You should use Windows API calls to put text in the clipboard to be safe.

  3. #3
    Board Regular
    Join Date
    Nov 2009
    Posts
    219
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: PutInClipboard Office 365


  4. #4
    Board Regular gallen's Avatar
    Join Date
    Jun 2011
    Location
    Manchester UK
    Posts
    1,896
    Post Thanks / Like
    Mentioned
    21 Post(s)
    Tagged
    1 Thread(s)

    Default Re: PutInClipboard Office 365

    ahhh! Of course. I forgot to mention they upgraded to Win 10 from Win7. Many thanks

    - forum use guidelines, forum rules and terms of use

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


  5. #5
    Board Regular Jaafar Tribak's Avatar
    Join Date
    Dec 2002
    Location
    Larache--Morocco
    Posts
    7,389
    Post Thanks / Like
    Mentioned
    40 Post(s)
    Tagged
    3 Thread(s)

    Default Re: PutInClipboard Office 365

    Another clipboard tool that might work :
    Code:
    Function SetClipBoardText(ByVal Text As Variant) As Boolean
        SetClipBoardText = CreateObject("htmlfile").ParentWindow.ClipboardData.SetData("Text", Text)
    End Function
    
    Function GetClipBoardText() As String
        On Error Resume Next
        GetClipBoardText = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("Text")
    End Function
    
    Function ClearClipBoardText() As Boolean
        ClearClipBoardText = CreateObject("htmlfile").ParentWindow.ClipboardData.clearData("Text")
    End Function

    Code:
    Sub Test()
        SetClipBoardText "Hello"
        MsgBox GetClipBoardText
        ClearClipBoardText
        MsgBox GetClipBoardText
    End Sub
    Office/Excel 2010 64Bits -- Win10 64Bits

    Common sense is not so common.


    http://photo-larache.blogspot.com/

  6. #6
    Board Regular gallen's Avatar
    Join Date
    Jun 2011
    Location
    Manchester UK
    Posts
    1,896
    Post Thanks / Like
    Mentioned
    21 Post(s)
    Tagged
    1 Thread(s)

    Default Re: PutInClipboard Office 365

    Quote Originally Posted by Jaafar Tribak View Post
    Another clipboard tool that might work :
    Code:
    Function SetClipBoardText(ByVal Text As Variant) As Boolean
        SetClipBoardText = CreateObject("htmlfile").ParentWindow.ClipboardData.SetData("Text", Text)
    End Function
    
    Function GetClipBoardText() As String
        On Error Resume Next
        GetClipBoardText = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("Text")
    End Function
    
    Function ClearClipBoardText() As Boolean
        ClearClipBoardText = CreateObject("htmlfile").ParentWindow.ClipboardData.clearData("Text")
    End Function

    Code:
    Sub Test()
        SetClipBoardText "Hello"
        MsgBox GetClipBoardText
        ClearClipBoardText
        MsgBox GetClipBoardText
    End Sub
    This works a treat. Nice workaround.... Thank you

    - forum use guidelines, forum rules and terms of use

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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