Dialog for user to select a worksheet?

In Access VBA I use Application.FileDialog to select a file but how can I select a workbook and then the specific worksheet?
LVL 1
Jess31Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
your question is so vague.
what do you intend to do after selecting the excel file?
 - open the excel file than select the specific worksheet
- do you want to import the content of the worksheet?
   docmd.transferspreadsheet acimport, "tablename", strexcelfile, true, "NAMEOFSHEET!"
Rgonzo1971Commented:
Hi,

You could use a listbox

Private Sub UserForm_Initialize()
Dim aSheets
Dim strSheets As String
For Each xlSheet In ActiveWorkbook.Worksheets

    strSheets = strSheets & ";" & xlSheet.Name
Next xlSheet

strSheets = Right(strSheets, Len(strSheets) - 1)
aSheets = Split(strSheets, ";")
ListBox1.List = aSheets
End Sub

Open in new window

Regards

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeOwner, Developing Solutions LLCCommented:
I use a technique similar to that used by Rgonzo1971
Jeffrey CoachmanMIS LiasonCommented:
On the other side of things, ...Notice that here you are simply simulating the Access built in Import wizard
(Select the file, ...then select the sheet.)
Browse to fileSelect File dialog boxSelect Sheet
So instead of going through all this code, ...why not just use the wizard?:

The advantages are:
1. Only one line of code is needed:
    DoCmd.RunCommand acCmdImportAttachExcel
2. With the wizard you can select things like:
a. Append, of Import, or Link
b. First Row contains field names
c. You can rename fields
d. you can change datatypes
e. Let Access add a primary Key
f. the ability to move back and forth through the wizard
...etc

Why reinvent the wheel?

JeffCoachman
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.