• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Combobox to open specific file selected

Bimmy

Member
Hello,

Column A has general file names, Column B has file names associated with files from Column A and Column C has path to all the files.

Column A-----Column B----- Column C
---AA-------Main Sheet-----D:\AA\Main.xlsb
---AA-------Source Sheet---C:\AA\Source.xlsx
---BB-------Instruction------D:\BB\Instruction.txt
---CC-------Test---------- --D:\CC\Test.docx

I have 2 combobox. First combobox will list files from Column A and second will list files from Column B.

The idea is, if I select AA from first combobox and select Main Sheet from second combobox and click on commandbutton, the userform should open the selected file.

No matter what the file type is, userform should open it. Mostly the files will be
excel,word,text,pdf.

Below are the codes that is used to populate both the comboboxes.

Code:
Private Sub cbPrimary_Change()

    Dim Name As String, R(), Counter As Integer, I As Integer
    Name = cbPrimary.Value
 
    For Counter = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        If Cells(Counter, 1).Value = Name Then
            I = I + 1
            ReDim Preserve R(I - 1)
            R(I - 1) = Cells(Counter, 2).Value
        End If
    Next Counter
 
    UFSelection.cmSecondary.List = R
 
End Sub


Code:
Private Sub UserForm_Initialize()

    Dim Counter As Integer
 
    With CreateObject("Scripting.Dictionary")
        For Counter = 1 To Cells(Rows.Count, 1).End(xlUp).Row
            .Item(Cells(Counter, 1).Value) = ""
        Next Counter
        cbPrimary.List = .keys
    End With
     
End Sub

I'm not able to initialise the userform as soon as the sheet opens.

Have attached sample sheet.

Requesting all excel experts to go through the codes and do necessary changes and addition to achieve the idea.
 

Attachments

  • UF.xlsm
    18.5 KB · Views: 10
Hi Marc L,

Thanks for responding.

I'm a newbie and got the excel with the code from googling.

I'll be grateful if you can help me with the code. Request you to go through the attachment and do the needful.
 
Back
Top