Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Saving the content of the clipboard and restoring it in VB

Posted on 2004-04-16
Medium Priority
Last Modified: 2010-05-02
Hi I wrote a program which uses the clipboard. But I dont want to loose the content that was in the clipboard before i used it..
I have checked everywhere on the net to find a sample program that can save no matter what from the clipboard and restore it to the clipboard afterwards. I have found some that can save and restore some things like text pictures etc. but they were not ble to save everything.

So if there is anybody who is able to write a function that can do that. id be very thankful.
Question by:AIDeton
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Expert Comment

ID: 10843459
I think you can use the 'GetText' method of the clipboard object and then save it to a file ...

Temp = Clipboard.GetText(vbCFText)
Open app.path & "\Clip.txt" For Output As #1
Print #1, Temp
LVL 17

Expert Comment

ID: 10848550
>> I think you can use the 'GetText' method of the clipboard object and then save it to a file ...

GetText is for Text only and won't apply to objects.

>> So if there is anybody who is able to write a function that can do that. id be very thankful.


The above is a start on how to go about it. Main reason for the link is to take note on how to Get/Set "File Lists" (when you select files in Explorer and chose "copy").



The above provide information on the formats and operations. Pay attention to how the clipboard data is stored for different formats and how it is suggested to go about retrieving the data... (quote below).

"To retrieve paste information from the clipboard, a window first determines the clipboard format to retrieve. Typically, a window enumerates the available clipboard formats by using the EnumClipboardFormats function and uses the first format it recognizes. This method selects the best available format according to the priority set when the data was placed on the clipboard."

Author Comment

ID: 10906976
hey zzzzzooc,
the program from vb-helper seems to be exactly whyt I need. unfortunately I do not seem to have the knowlege on how to use the clipboardsetfiles() function. i do not know what i have to give it as parameter. it says something like an arrey file_names().
I have already tried some things but nothing seems to be working.

and I cant see how it is used because the function is in the exampleprogram but not used at all.

I'd be glad If you could explain to me how i have to use it.

thanks for your help
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 10963772
Hey guys I really need your help I would appreciate if you could tell me how to use the restore function.
I am in a lot time pressure so i will increase the points(250-350) hopeing that you will help me then.

Thank You
LVL 17

Accepted Solution

zzzzzooc earned 750 total points
ID: 11258790
Sorry, an overlooked question.

It's most-likely too late and I apologize but all you had to do was pass an array populated with file-names to the function such as:

    Dim MyArray(2) As String
    MyArray(0) = "c:\test1.txt"
    MyArray(1) = "c:\test1.txt"
    MyArray(2) = "c:\test1.txt"
    Call ClipboardSetFiles(MyArray)

My suggestion for the question is either accept answer / PAQ & refund.

Author Comment

ID: 11287746
yeah it is a little bit late but we cant change that. thank you anyways that you answered the question i dont have time to test the code but i will next week or so...
here are the points.


Author Comment

ID: 11350956
Hi Zzzzzzooc,
I know i am kinda late with this and that i have already accepted your answere but i have a lil problem... I foudn time today to try out the function you gave me. the problem is when i add your code to a function it will write c:\test1.txt
3 times into the clipboard. I mean okay now i know howto write text into the clipboard but i need to write the data back into the clipboard that had been there shortly before, which can be everything... maybe contacting each other would be easier if we exchanged e mail adresses or ICQ#. I promise i will give you further points if you help me solve this problem.
It is still very important for me to solve/ understand this problem.

ICQ: 110093435
Email: simon@simonweiss.de
LVL 17

Expert Comment

ID: 11352705
It's best to keep any help provided here.

ClipboardSetFiles() sets every item in the array into the clipboard.

    MyArray(0) = "c:\test1.txt"
    MyArray(1) = "c:\test1.txt"
    MyArray(2) = "c:\test1.txt"

Since there are 3 items in the clipboard, all 3 will be copied to the clipboard. If you removed MyArray(1) and MyArray(2), only one would be copied to the clipboard.

The function ClipboardGetFiles() returns an array such as MyArray() with all of the items from the clipboard. All you would need to do is pass the array from ClipboardGetFiles() to ClipboardSetFiles(). I hope that's enough to resolve that.

Since it seems you aren't too familiar with all of the aspects of VB, you may want to search Yahoo! for tutorials/guides or buy/read books.

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question