Use Selected Items in Multi Listbox To Perform Actions

jamer02

New Member
Joined
Jul 5, 2011
Messages
4
Hey guys,

I have a multiselect listbox which lists all the files within a certain folder, but I am unable to work out how to do the following:

For each selected item (which is the name of a file), I want it to open these files in turn, print out two copies of sheet 1 and then close and delete each file.

I will then be left with two printed copies of each file that has been ticked by the user and the corresponding file wiped from the hardrive.

Any ideas guys?

Many Thanks

Jamer
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
What action do you need help with? Because these are all standard actions in Excel VBA, at least in the help files and here on the board you will find thousands and thousands of topics with code for it.
 
Upvote 0
I cannot seem to find any specific to what I need, which is use the name of a selected item to match this exactly to a file name in a certain folder, for that file to then be opened, printed then deleted.

I really do appreciate your feedback.

Jamer
 
Upvote 0
What are the items called in the listbox, and what are the EXACT file locations on the filesystem?
 
Upvote 0
If you Google on:

excel vba listbox loop through selected items

and take the 1st site it returns, you already have the loop... Opening a file is done with Workbooks.Open. Printing a sheet with .PrintOut and closing a file with .Close. Deleting a file is done with Kill.
 
Upvote 0
OK, so for example the listbox lists all the file names from the directory "C:\Users\James\Documents\TEST\", using the following code:

Code:
Private Sub userform_Initialize()
  c00 = "C:\Users\James\Documents\TEST\"
  c01 = Dir(c00 & "*.*")

  Do Until c01 = ""
    c02 = c02 & "|" & c01
    c01 = Dir
  Loop

  ListBox1.List = Split(Mid(c02, 2), "|")
End Sub

I know want the selected items in this listbox (which are of course files in essence), to be opened, printed, closed and deleted.

Now, why I am getting confused over this is because I am not sure how to use the name of the selected item in the listbox to find the corresponding file in the directory to perform the actions.

I hope this helps you help me.

Many Thanks

Jamer
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top