MITH Posted September 19, 2014 Share Posted September 19, 2014 I am writing a code in Excel (VBA) to get the Clipboard contents using the Autoit DLL. But I am not able to get it work. It is giving wrong Output. Here is my code: Public Declare Sub AU3_ClipGet Lib "C:\Windows\System32\AutoItX3.dll" (ByVal szClip As LongPtr, ByVal nBufSize As Integer) Sub Autoit_ClipGet() Dim ClipPtr As LongPtr, ClipContents As String, StrClip As String StrClip = "" ClipPtr = StrPtr(StrClip) AU3_ClipGet ClipPtr, Len(ClipPtr) MsgBox ClipPtr End Sub Am I missing something? Not Sure. Expecting some expert advice to get this work. Please help. Thanks in advance for help. Link to comment Share on other sites More sharing options...
Solution funkey Posted September 19, 2014 Solution Share Posted September 19, 2014 (edited) I did not test the AU3_DLL with excel, but you could get the clipboard contents this way: http://excel-macro.tutorialhorizon.com/vba-excel-get-text-from-the-windows-clipboard/ Edit: Tried both versions with success: Const DATAOBJECT_BINDING As String = "new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}" Public Declare Sub AU3_ClipGet Lib "C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.dll" (ByVal szClip As Long, ByVal nBufSize As Integer) Public Function PasteFromClipboard() As String On Error GoTo Whoa With CreateObject(DATAOBJECT_BINDING) .GetFromClipboard PasteFromClipboard = .GetText End With Exit Function Whoa: 'If Err <> 0 Then MsgBox "Data on clipboard is not text or is empty" 'PasteFromClipboard = "" End Function Public Sub ShowTextFromClipBoard() If (CountClipboardFormats() = 0) = True Then MsgBox "Clipboard is empty" Else MsgBox PasteFromClipboard() End If End Sub Sub Autoit_ClipGet() Dim StrClip As String StrClip = Space(2048) AU3_ClipGet StrPtr(StrClip), 2048 MsgBox StrClip End Sub Edited September 20, 2014 by funkey MITH 1 Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
MITH Posted September 21, 2014 Author Share Posted September 21, 2014 Thank You. The Autoit_ClipGet() function works perfectly. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now