Fill Multi Select ListBox With File Paths & Open Selected Files
Nov 26, 2008
i'm having a problem with a script I have (script is below). What i'm doing is running a script that displays files in a certain folder, those files are then displayed on sheet1 column O and are linked so when they are clicked upon, the file will open. I also have a combo box with a input range of $O$O. That puts the values in column O in the combo box. Now here is a problem and request.
Problem first, when I select the file names from the combo box, they don't open the file, all it does is display the file name in combo box and that's it. how to I get it to open up the file? Now for a request, I have another sheet that is almost exactly as the one i described above. The only thing different I want is when someone clicks on a file name from the combo box, instead of it automatically linking to the file, I want them to click on a button to display the file.
Dim lCount As Long
Application. ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
'Change path to suit
.LookIn = "c:Sec"
.FileType = msoFileTypeExcelWorkbooks
' .Filename = " Book*.xls"..................
I have a listbox with 8 columns. Multiselect is enabled, and it must stay this way. As part of my program, after the user presses a command button, I need to use the row indexes of the selected rows in order to copy the selected information into an array which is then placed in a different listbox, and then delete the items from the original list. Pseudocode of what I want to do:
But my understanding is that .ListIndex does not work this way with multiselect listboxes. I've tried searching for a solution for a while, but I cannot find one.
I have a listbox that has row and columns. The rows are combinations of options and the columns are Additives.
After selecting a row in Listbox1, (first column are names) i would like the value of the second column to goto a specific area.... find that value and in the cell to the right of it place a "Y". The "Y" would indicate that "yes" it was part of the selection row of the listbox. Same for third column, forth, fifth and sixth. The result from the listbox is a number of Y's and N's in the result page. Then making all that were not part of selected line and equal to "N" to hide row (height = to zero).
Listbox and expected result are in attached example worksheet.
The attached does show the need much better then I can explain it.
changing two variables a various amount of times and running the same procedure and copying the resutls into another sheet. Seems like a perfect place for a macro. However, these variables can be chosen from a list that the user wants. So why not build in a listbox for each one. Now I have two listboxes one for variable A and one for variable B.
The procedure in theory goes something like this we change variable A from the base case and then run the procedure for variable B, get the results, then run the scenario again but changing only variable B abnd repeat. Then once, all of the variable B scenarios are done, I want to change the variable A and then repeat and so forth.
That is the background and my main problem at this point, is that have these values in two listboxes, I know how to do the for each loops and such, however, I do not know how to do them for values in the listbox.
How do I identify the values selected in the respective listboxes and then pull them so I only use them for the for each loop?
I've got a listbox (ListBox1) and it lists 5 files. names are One, Two, Three, Four, Five (all .xls) and they're saved in C:/MyFolder
What i want to do, when a user clicks a button, for a code to only open the files that are selected. So for example, the user selects Three.xls and Five.xls - the code would need to ignore the others and open the selected files.
The main file was linked to other files. Instead of using the "edit links" dialogue box provided by Excel, I wish to use a list box. This list box will show all the files that the main file is linked to.
The user will have the the option to single select or multiple select the files. Upon clicking "ok" it will "open and close" the selected files, thus updating the main file. (it should also remove the update links dialogue box of the source files if they had it, it will be a hassle for the user to click on the "don't update" for every linked file that is open)
I know the update links in Excel is able to do it but the links sometimes will result in errors, beside it doesn't offer multiple selections.
i would like to use the application.getopenfilename to select multiple files, then with these file's would like to be able to use them to create a email with these files as the attachment. then move the files to a new location and delete the originals.
Split off from Fill Multi Select ListBox With File Paths & Open Selected Files
if I can add a other request I just thought of.
If a sheet is also in one of the workbooks list, can I add a link directly to it? For example, Workbook1 has a sheet named "MARCH".
When i'm working on sheet "MARCH" I want to be able to click on a button to see the Userform I created from the script above and see if the sheet "MARCH" is present from the other workbooks listed, if there is a sheet "MARCH" in the workbooks listed, I want another listbox to show what files contain sheet "MARCH" and link to them.
I have a multiselect listbox with values that gets populated from a sql statement, and I would like to get is the first or second index from the selected item. I know how to get the listindex from a combobox by using:
VB: cbnumber.List(.ListIndex, 0)
How can I loop through and get the 1st index number for the selected items only from the listbox? I want to pass this index number to another sql statement.
I am using this code to hide or unhide rows of text on another sheet:
VB: Sub ProcessSheet1ChangeOnCellJ7(ByVal Target As Range)
Dim sAddress As String Dim sValue As String
'Get the address of the cell that changed without '$' signs sAddress = Target.Address(False, False)
When the "Not Pursuing" list box option is selected (in cell "J7" or "J8" in Sheet 1) I need to add (or over-write) "Not Pursuing" to the range of cells in column "B" (in the "Tasks" sheet), but only for that particular Goal, meaning a limited range of cells in column "B". If the "Pursuing - Show All Tasks" option is selected for a Goal then these same cells need to be blank so that the appropriate person can enter their name into the cell.
The purpose for adding "Not Pursuing" automatically to these yellow highlighted cells is that it will facilitate filtering of tasks by individual in the "Tasks" sheet..
Again I have tried several times to upload a sample file and am unable to, which I know makes it more difficult to solve. (Is there some common mistake people make? I know it's an allowed format and is very small in file size....)
Code solution can be entered directly beneath:
VB: If Target.Value = "Not Pursuing" Then ActiveWorkbook.Sheets("Tasks").Rows("29:29").EntireRow.Hidden = False ActiveWorkbook.Sheets("Tasks").Rows("30:48").EntireRow.Hidden = True
I have a mulit-extended listbox, a textbox and a button on a form.
I have populated the listbox with a list of files from a directory no problems.
First Part (Single Selection):
When I click on one/single filename in the list I want:
1. The textbox to be populated with the name I have selected
2. When I click the button (With the single filename selected, I want to call a function passing the filename I have selected.
The function could contain a msgbox(selecteditemname) for now.
Second Part (Multi Selection):
When I multi select filenames from the list I want:
1. The textbox to be populated with "Multiple Files Selected"
2. When I click the same button as before (With multiple filenames selected, I want to call a different function and pass each filename individually in may be a for loop)
The function could contain the loop and with each filename in the loop msgbox(selecteditemname)
I have tried the above and noticed that the listbox1.value property for multi listboxes dont seem to work and I am not really sure how to distinguish between one selection or multiselection to get a button to pass off to two separate functions.
I am currently setting up a userform where one of the options is for an error code (chosen from a listbox) but the user has to be able to select multiple codes. I have the below working if it is NOT multi select, works a dream and goes in the right column.
VB: If ListBox2.Text = "A1" Then LastRow.Offset(1, 20).Value = "x" ElseIf ListBox2.Text = "A2" Then LastRow.Offset(1, 21).Value = "x"
But as soon as I set it to mutliselect and choose say A1 and A2 neither one writes, I imagine because Listbox2.text is now A1,A2 and not just one or the other.
I'm trying to populate a dropdown Combo Box by using conditions.
In the example I attached...I would be trying to use ComboBox1.ListFillRange to populate the ComboBox only with players who have "C" in the Position column and "ANA" in the Team Code Column. Which would give me all the Catchers on the Angels.
I want to add a msgbox with a no selection error to a multi select listbox I have. For a dropdown I just use "if .ListIndex =-1" but listindex doesn't seem to work. I'm playing with .selectedindex but it's not playing ball
I have a multiselect listbox in a worksheet that the user can select from. When the file is saved, closed and reopened, the user selections disappear. Is there a way of reloading the previous selections when the file is reopened? I have used the listbox from the control toolbox and have Excel 2003. My VB experience is very limited!!
I am trying to create a data entry form with a text field and a listbox. The list box is populated by another sheet and the text box will be used to enter names. I need to be able to enter a new name, select multiple options from the list box and then click a button to add this info to a sheet in excel.
I have read about changing the list options to allow this etc - the problem is I can't get the results to go back into excel - all I get is a name with nothing from the listbox.
I have a listbox that is automatically filled with data in two columns through a lookup function from a worksheet. That works fine. But now I want to fill the third column with data through a text box, but only in the rows I have selected in the listbox.
My code so far is:
The number I want to insert into the listbox appears, but not in column 3 in the selected row(s).
I have this workbook with 22 sheets and 21 are hidden. On the one open sheet there is a button that opens a userform with a listbox. I have radio buttons on the side to control whether the list box allows single selection, multiple selection, and extended selection. I want to change extended to open all sheets.
Anyway, I have the list box populated but I can't figure out how to code opening single sheets, multiple sheets, or all sheets depending on the radio button selected when the OK button is pressed. I know the listbox depends on the selected property but I am stuck. Here is the code I had but it is a mess. I am still new to VBA.
Private Sub OKButton_Click() Dim Msg As String Dim i As Integer Dim UserSheet As Object If ListBox1.ListIndex = -1 Then Msg = "Please select a sheet." Else Msg = "" For i = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(i) Then For Each i In ListBox1..........................
Arised from my earlier posting in Populate ComboBox With Specific Sheet Column Range. I have the following working code below, but am having trouble finding coding examples to select specific cells from the selected row (that was found by selecting a ComboBox value)and update TextBoxes with those individual values after the UserForm has been initialized (the bold "GREEN" comment in the code below). I have been able to find plenty of references to update TextBox values to Cells, but that doesn't do me much good in this application since the User needs to verify the old data in these cells before updating them using the UserForm TextBoxes.
I was toying around with several different variations of code (none of which worked properly), so I left it out for clarity of my working code. I'll post up this non-working code as needed, because I really wanted a fresh answer...not what I was trying to do. The attached file should be sufficient to see what's going on
Private Sub UserForm_Initialize() With Sheets("SR Information") .Range("A2", .Cells(Rows.Count, "A").End(xlUp)).Name = "MyRange" End With SRnumber.RowSource = "MyRange" End Sub
Private Sub SRnumber_Change() Dim ServiceRequestNumber As String Dim c As Range Dim rngG As Range Sheets("SR Information").Select With Selection ServiceRequestNumber = SRnumber.Value For Each c In Intersect(ActiveSheet.UsedRange, Columns("a")) If c = ServiceRequestNumber Then..................
Dim myname As String myname = Application. GetOpenFilename
I use it to attempt to open first a QuickBooks file and then an excel workbook. The Quickbooks file opens fine. The Excel workbook never appears to open but I do get the full file pathname to my excel workbook returned which I then parse off to get just the workbook name.
Why would it behave this way? I open both these files manually all the time.
Also, I'm trying to use a filter as follows:
myname = Application.GetOpenFilename("*.QBW")
I get a compile error saying that I'm calling the function wrong.
I am using formulas that use ranges in outside file locations. Due to my company's file management "nuances" the file paths are exceedingly long and make it difficult to read formulas. Can I use the Define Name feature to enter the external file path and file name? My attempts so fare don't seem to be working.
Public Sub Populate() Dim lawSheet As Worksheet Dim achSheet As Worksheet Workbooks.Open ("\bankrec recsACHACH.xls") Set lawSheet = Workbooks("Lawson JE Upload Template.xls").Worksheets("Input") Set achSheet = Workbooks("ACH.xls").Worksheets("ACH")
to be able to select the "achSheet". The file will need to be selected from T:ACH. This code is over my head and I'm hoping just the beggining can be edited as to not jack up the rest. If I have to paste the code I will. its big but not huge.
I have this that I use on a completely different workbook that lets you select the file, but I don't know how to "make it work" with this application, but the idea of selecting the sheet is what I want.
Dim OpenA As Workbook, OpenB As Workbook Dim TheFile As String
Set OpenA = ActiveWorkbook
ChDrive "E:" ChDir "E:QueriesComp Store SalesMicroStrategy Comp Store Reports "
TheFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , "Select the file and choose open.") If TheFile = "False" Then Exit Sub End If Workbooks.Open Filename:=TheFile
I've created a Form (Userform1) and a Listbox(ListBox1). The listbox is initialized by creating a File System Object so that all XLS files within a folder(Test1) are added to the Listbox. I have a Sub to call the form from a workbook. The files saved in the "Test1" folder appears in the list but I get an error when I select and launch the command to open.
Private Sub UserForm_Initialize() Dim fso As FileSystemObject Dim fld As Folder Set fso = New FileSystemObject Set fld = fso.GetFolder("c:Documents and SettingsEricDesktopTest1") For Each Fil In fld.Files If UCase(Right(Fil. Name, 3)) = "XLS" Then ListBox1.AddItem Fil.Name End If Next End Sub
Code to open workbook from the listbox
Private Sub CommandButton1_Click() Workbooks.Open ActiveWorkbook.Path & "" & ListBox1 UserForm1.Hide End Sub