Solved

Saving the content of the clipboard and restoring it in VB

Posted on 2004-04-16
9
217 Views
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.
0
Comment
Question by:AIDeton
  • 4
  • 3
9 Comments
 
LVL 6

Expert Comment

by:mmusante
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
0
 
LVL 17

Expert Comment

by:zzzzzooc
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.

http://www.vb-helper.com/howto_track_clipboard.html

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").

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardformats.asp?frame=true

http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardoperations.asp?frame=true


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."
0
 

Author Comment

by:AIDeton
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
0
 

Author Comment

by:AIDeton
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
AIDeton
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 17

Accepted Solution

by:
zzzzzooc earned 250 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.
0
 

Author Comment

by:AIDeton
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.

AIDeton
0
 

Author Comment

by:AIDeton
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.

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

Expert Comment

by:zzzzzooc
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.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now