Solved

Saving the content of the clipboard and restoring it in VB

Posted on 2004-04-16
9
229 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
[X]
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
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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
 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access query that references subform 5 49
Getting warning: You are about to delete 1 row(s) 9 59
VB6 ListBox Question 4 61
backup program with robocopy 6 87
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

742 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