Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy all items from a listbox

Status
Not open for further replies.

hugh999

MIS
Joined
Nov 29, 2001
Messages
129
Location
IE
I have written a piece of code that will populate a list box with file names from a specified folder location.

How can i select all the file names in the list box and copy them to clipboard, so i can paste them to a txt file.

I appreciate your help

Hugh
 

The Following will retrieve all of the items from a list box and then copy the information to the clipboard.

[tt]
Dim I As Integer, S As String

For I = 0 To List1.ListCount - 1
S = S & List1.List(I) & vbNewLine
Next I

Clipboard.Clear

Clipboard.SetText S, vbCFText
[/tt]

But on the other hand there is really no need to copy the contents to the clipboard to put into a text file. You could write the textfile yourself...

[tt]
Dim FName As String, FNumb As Integer

FName = "Your Path and File Name"
FNumb = FreeFile

Open FName For Append As #FNumb
Print #FNumb, S
Close #FNumb
[/tt]

I hope this helps, Good Luck


 
Thanks for your help, my code works great now. Just 1 other question, how would i overwrite text on an existing text file with data from my list box.

Thanks
Hugh
 

Instead of open the file for "Append" open it for "Output"

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top