Last active
December 23, 2021 21:32
-
-
Save Se7enSquared/ae990702f36a028429dc865a6704c391 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'EXAMPLE CALL: | |
' To clipboard: | |
' Dim string_to_copy As String: string_to_copy = ThisWorkbook.Worksheets("Sheet1").Range("A1").Value | |
' Clipboard (string_to_copy) | |
' From clipboard: | |
' Dim in_clipbaord As String | |
' in_clipboard = Clipboard() | |
'------------------------------------------------------------------ | |
' Function: Clipboard | |
' Purpose: Read from (if no variable passed) or write variable | |
' passed to clipboard | |
' Params: String: text_to_copy (Optional) if null, reads from the | |
' clipboard. If not null, writes text_to_copy to clipboard | |
' Last Update: 11/23/2021 | |
' Author: Gray | |
'------------------------------------------------------------------ | |
Function Clipboard(Optional text_to_copy As String) As String | |
'PURPOSE: Read/Write to Clipboard | |
'Source: ExcelHero.com (Daniel Ferry) | |
Dim text_to_copy_variant As Variant | |
'Store as variant for 64-bit VBA support | |
text_to_copy_variant = text_to_copy | |
'Create HTMLFile Object | |
With CreateObject("htmlfile") | |
With .parentWindow.clipboardData | |
Select Case True | |
Case Len(text_to_copy) | |
'Write to the clipboard | |
.setData "text", text_to_copy_variant | |
Case Else | |
'Read from the clipboard (no variable passed through) | |
Clipboard = .GetData("text") | |
End Select | |
End With | |
End With | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment