Asking user to pick a file name in userform...

  • Thread starter Thread starter Trevor
  • Start date Start date
T

Trevor

Hi all,

I am trying to have a userform pop up in the beginning of
a macro to give the user three options, lpt26, lpt27, or
lpt28. By selecting the one they prefer from a combo box,
let's say, that value needs to be inserted at the end of
the statement:

Workbooks.OpenText FileName:="G:\Collections\lpt28.txt"

How do I assign their selection to a variable and add it
to the open workbook call? Any help would be much
appreciated.

Thanks,

Trevor
 
Option Explicit

Private Sub CommandButton1_Click()
Workbooks.OpenText Filename:="T:\Collections\" &
ComboBox1.List(ComboBox1.ListIndex) & ".txt"
End Sub

Private Sub UserForm_Initialize()
ComboBox1.List = Array("lpt26", "lpt27", "lpt28")
ComboBox1.ListIndex = 0
End Sub

Assumes you have a button that triggers the open.

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top