+ Reply to Thread
Results 1 to 9 of 9

Copy to Clipboard and so that I may paste to any other program

  1. #1
    tomwashere2
    Guest

    Copy to Clipboard and so that I may paste to any other program

    I would simply like to know how to specify that I would like to store a
    variable value to the clipboard so that I can paste that information to other
    programs at my own discretion. Thanks!!!

  2. #2
    Gary''s Student
    Guest

    RE: Copy to Clipboard and so that I may paste to any other program

    Review this discussion:

    http://groups.google.com/group/micro...fa7b9c45b74d89


    --
    Gary's Student


    "tomwashere2" wrote:

    > I would simply like to know how to specify that I would like to store a
    > variable value to the clipboard so that I can paste that information to other
    > programs at my own discretion. Thanks!!!


  3. #3
    NickHK
    Guest

    Re: Copy to Clipboard and so that I may paste to any other program

    There's also the MSForms.DataObject you can work with.

    NickHK

    "tomwashere2" <[email protected]> wrote in message
    news:[email protected]...
    > I would simply like to know how to specify that I would like to store a
    > variable value to the clipboard so that I can paste that information to

    other
    > programs at my own discretion. Thanks!!!




  4. #4
    tomwashere2
    Guest

    Re: Copy to Clipboard and so that I may paste to any other program

    Can you give me the vba code sample on how to use it?



    "NickHK" wrote:

    > There's also the MSForms.DataObject you can work with.
    >
    > NickHK
    >
    > "tomwashere2" <[email protected]> wrote in message
    > news:[email protected]...
    > > I would simply like to know how to specify that I would like to store a
    > > variable value to the clipboard so that I can paste that information to

    > other
    > > programs at my own discretion. Thanks!!!

    >
    >
    >


  5. #5
    NickHK
    Guest

    Re: Copy to Clipboard and so that I may paste to any other program

    VBA Help has a working example.

    NickHK

    "tomwashere2" <[email protected]> wrote in message
    news:[email protected]...
    > Can you give me the vba code sample on how to use it?
    >
    >
    >
    > "NickHK" wrote:
    >
    > > There's also the MSForms.DataObject you can work with.
    > >
    > > NickHK
    > >
    > > "tomwashere2" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > I would simply like to know how to specify that I would like to store

    a
    > > > variable value to the clipboard so that I can paste that information

    to
    > > other
    > > > programs at my own discretion. Thanks!!!

    > >
    > >
    > >




  6. #6
    Patricia Shannon
    Guest

    Re: Copy to Clipboard and so that I may paste to any other program

    I am trying to do the same thing. You can move data from the dataobject to
    the clipboard. But as far as I can tell, you can only put data in the data
    object from the clipboard or from a forms textbox.

    "tomwashere2" wrote:

    > Can you give me the vba code sample on how to use it?
    >
    >
    >
    > "NickHK" wrote:
    >
    > > There's also the MSForms.DataObject you can work with.
    > >
    > > NickHK
    > >
    > > "tomwashere2" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > I would simply like to know how to specify that I would like to store a
    > > > variable value to the clipboard so that I can paste that information to

    > > other
    > > > programs at my own discretion. Thanks!!!

    > >
    > >
    > >


  7. #7
    Patricia Shannon
    Guest

    RE: Copy to Clipboard and so that I may paste to any other program

    I need to do the same thing. I found the DataObject useless, because the
    only way I could find to put data in it was from the clipboard or from a
    textbox.
    My browser wouldn't let me access the link. Thinks it's Chat.


    "Gary''s Student" wrote:

    > Review this discussion:
    >
    > http://groups.google.com/group/micro...fa7b9c45b74d89
    >
    >
    > --
    > Gary's Student
    >
    >
    > "tomwashere2" wrote:
    >
    > > I would simply like to know how to specify that I would like to store a
    > > variable value to the clipboard so that I can paste that information to other
    > > programs at my own discretion. Thanks!!!


  8. #8
    Patricia Shannon
    Guest

    RE: Copy to Clipboard and so that I may paste to any other program

    After wasting a lot of time trying to find a straightforward way to do this,
    I created the following subroutine that opens a workbook, puts the variable
    (passed to the subroutine as an argument) in cell A1, copies that to the
    clipboard, then closes the new workbook. With all the great things that can
    be done with VBA and Excel, I would think there would be an easier way to do
    this.

    Public Sub CopyToClipboard(VariableToBeSaved)
    ' created by Patricia Shannon Aug. 22, 2006
    ' Copy variable to Clipboard

    Workbooks.Add
    Cells(1, 1) = VariableToBeSaved
    Cells(1, 1).Copy
    ActiveWorkbook.Close savechanges:=False

    End Sub

    In the subroutine where you need to save the variable, you would have
    copytoclipboard(yourvariablehere)
    "tomwashere2" wrote:

    > I would simply like to know how to specify that I would like to store a
    > variable value to the clipboard so that I can paste that information to other
    > programs at my own discretion. Thanks!!!


  9. #9
    NickHK
    Guest

    Re: Copy to Clipboard and so that I may paste to any other program

    Patricia,
    You put text from anywhere to the clipboard with .SetText

    Private Sub CommandButton2_Click()
    Dim LongVal As Long
    LongVal = 25
    If SendToClipBoard(LongVal) = True Then ActiveSheet.Paste
    End Sub

    Function SendToClipBoard(AnyValue As Variant) As Boolean
    Dim DatObj As DataObject

    On Error GoTo Handler
    Set DatObj = New DataObject
    With DatObj
    .SetText CStr(AnyValue), 1
    .PutInClipboard
    End With
    SendToClipBoard = True
    Exit Function
    Handler:
    SendToClipBoard = False

    End Function

    Or there is always the various Clipborad API, which all methods will resort
    to in the end.
    'Example from KPD-Team 1999, URL: http://www.allapi.net/

    Const LR_LOADFROMFILE = &H10
    Const IMAGE_BITMAP = 0
    Const IMAGE_ICON = 1
    Const IMAGE_CURSOR = 2
    Const IMAGE_ENHMETAFILE = 3
    Const CF_BITMAP = 2
    Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal
    hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal
    dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As
    Long) 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
    Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As
    Long, ByVal hMem As Long) As Long
    Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal
    wFormat As Long) As Long
    Private Sub Form_Load()
    Dim hDC As Long, hBitmap As Long
    'Load the bitmap into the memory
    hBitmap = LoadImage(App.hInstance, "c:\windows\logow.sys", IMAGE_BITMAP,
    320, 200, LR_LOADFROMFILE)
    If hBitmap = 0 Then
    MsgBox "There was an error while loading the bitmap"
    Exit Sub
    End If
    'open the clipboard
    OpenClipboard Me.hwnd
    'Clear the clipboard
    EmptyClipboard
    'Put our bitmap onto the clipboard
    SetClipboardData CF_BITMAP, hBitmap
    'Check if there's a bitmap on the clipboard
    If IsClipboardFormatAvailable(CF_BITMAP) = 0 Then
    MsgBox "There was an error while pasting the bitmap to the clipboard!"
    End If
    'Close the clipboard
    CloseClipboard
    'Get the picture from the clipboard
    Me.Picture = Clipboard.GetData(vbCFBitmap)
    End Sub

    NickHK

    "Patricia Shannon" <[email protected]> wrote in
    message news:[email protected]...
    > After wasting a lot of time trying to find a straightforward way to do

    this,
    > I created the following subroutine that opens a workbook, puts the

    variable
    > (passed to the subroutine as an argument) in cell A1, copies that to the
    > clipboard, then closes the new workbook. With all the great things that

    can
    > be done with VBA and Excel, I would think there would be an easier way to

    do
    > this.
    >
    > Public Sub CopyToClipboard(VariableToBeSaved)
    > ' created by Patricia Shannon Aug. 22, 2006
    > ' Copy variable to Clipboard
    >
    > Workbooks.Add
    > Cells(1, 1) = VariableToBeSaved
    > Cells(1, 1).Copy
    > ActiveWorkbook.Close savechanges:=False
    >
    > End Sub
    >
    > In the subroutine where you need to save the variable, you would have
    > copytoclipboard(yourvariablehere)
    > "tomwashere2" wrote:
    >
    > > I would simply like to know how to specify that I would like to store a
    > > variable value to the clipboard so that I can paste that information to

    other
    > > programs at my own discretion. Thanks!!!




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1