Results 1 to 6 of 6

Thread: Excel VBA: How to get text fro0m clipboard?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145

    Excel VBA: How to get text fro0m clipboard?

    Hi all,

    In my Excell app I need to get text from clipboard, parse it and fill table...
    VBA does not support Clipboard object like in VB...
    I tried to use API functions, but every time it fails on CopyMemory function

    Any ideas??? Short example will be very useful!

    Thanks,

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    I wonder if your method is the best one. The simplest way of getting data from the clipboard is to Paste it into a worksheet and process there. You can always delete the sheet afterwards.

    If you have a text file containing data, delimited or not, use Application.WorkBooks.OpenText which will open the file and do all the work for you (best to record a macro using Excel menu File/Open).

    Visual Basic for Applications does, however, have a DataObject with methods Clear, GetFormat, GetFromClipBoard, GetText, PutInClipBoard, SetText, StartDrag.
    Code:
    '- partial code
    Dim MyDataObject As DataObject
    Set MyDataObject = New DataObject
    MyDataObject.GetFromClipBoard
    Regards
    BrianB
    -------------------------------

  3. #3
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Excel VBA: How to get text fro0m clipboard?

    Brian,
    I looked at this code, but doesn't seem to work without a form. I am trying to prevent pasting multiple columns in my excel sheet and am totally lost at the moment.

    Could you give it a shot?

    Regards,
    Abhijit
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  4. #4
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Excel VBA: How to get text fro0m clipboard?

    According to "VBA Developer's Handbook", you can use clipboard API's with VBA.

    VBAhack

  5. #5
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Excel VBA: How to get text fro0m clipboard?

    I do not have a copy of the developer's handbook.

    I feel that this is something that should be solvable by using excel object.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  6. #6
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Excel VBA: How to get text fro0m clipboard?

    Try a Google search, such as:

    http://www.google.com/search?hl=en&q=VBA+and+clipboard

    VBAhack

Posting Permissions

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



Click Here to Expand Forum to Full Width