473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Import an Excel Sheet with File Dialog

17
hi guys,

i had made a simple import menu for xlsx, xls and accdb files from the current project folder with fixed name. see below the xlsx_data_import.

Expand|Select|Wrap|Line Numbers
  1. Private Sub xlsx_Data_Import_Click()
  2.  
  3. On Error Goto ErrorHandler
  4.  
  5.     DoCmd.TransferSpreadsheet acImport, , "Data", Application.CurrentProject.Path & "\Data_Backup.xlsx", True, "Data!"
  6.  
  7.     Exit Sub
  8.  
  9. ErrorHandler:
  10.     MsgBox "No such file exists in this directory!"
  11.  
  12. End Sub
  13.  
now i would like to add a file dialog, so i can choose which file i actually wanna import. i was searching in internet but there attempts were so complicated and nothing worked for me.

can somebody help with a simple file dialog to import 1 file only?
Oct 3 '15 #1

✓ answered by ADezii

The following should work nicely for you. Be sure to set a Reference to the Microsoft Office XX.X Object Library.
Expand|Select|Wrap|Line Numbers
  1. With Application.FileDialog(msoFileDialogOpen)
  2.  .Filters.Clear
  3.    .Filters.Add "Excel Files", "*.xlsx,*.xls"
  4.    .Filters.Add "Access Databases", "*.accdb"
  5.  .FilterIndex = 1      'Excel Files
  6.  
  7.  .AllowMultiSelect = False
  8.  .ButtonName = "Open"
  9.  .InitialFileName = "C:\"
  10.  .Title = "Select a File to Import"
  11.  .InitialView = msoFileDialogViewDetails
  12.  
  13.    If .Show Then
  14.      DoCmd.TransferSpreadsheet acImport, , "Data", .SelectedItems(1), True, "Data!"
  15.    End If
  16. End With

3 5184
ADezii
8,834 Expert 8TB
The following should work nicely for you. Be sure to set a Reference to the Microsoft Office XX.X Object Library.
Expand|Select|Wrap|Line Numbers
  1. With Application.FileDialog(msoFileDialogOpen)
  2.  .Filters.Clear
  3.    .Filters.Add "Excel Files", "*.xlsx,*.xls"
  4.    .Filters.Add "Access Databases", "*.accdb"
  5.  .FilterIndex = 1      'Excel Files
  6.  
  7.  .AllowMultiSelect = False
  8.  .ButtonName = "Open"
  9.  .InitialFileName = "C:\"
  10.  .Title = "Select a File to Import"
  11.  .InitialView = msoFileDialogViewDetails
  12.  
  13.    If .Show Then
  14.      DoCmd.TransferSpreadsheet acImport, , "Data", .SelectedItems(1), True, "Data!"
  15.    End If
  16. End With
Oct 3 '15 #2
rod4
17
THANKS a lot!!!! it works like a charme!
Oct 3 '15 #3
ADezii
8,834 Expert 8TB
You are quite welcome.
Oct 3 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: nicholas | last post by:
What would be the best and easiest way to implement a web page that allows me to: - import an Ms Excel-sheet in a database on a Ms Sql 2000 Server - this should be done through an asp.net...
1
by: gotgame0314 | last post by:
I am new to asp.net and would like to know the easiest way to view an Excel file in my asp app.
6
by: vj83 | last post by:
Hi, I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form. The code is here private void Button2_Click(object sender,...
6
by: Sport Girl | last post by:
Hi all , i need to write into an excel sheet file the data retreived from the database. i have the script but the problem is that i can't get the data written in the excel file. Can anybody help...
3
by: inepu | last post by:
I have some excel sheets that I would like to manage in access. I've created the access tables and relationships; the excel sheet is only one table and with duplicate data, I'd like to make sure that...
0
by: MBlock316 | last post by:
Hello everyone, I am trying to import a Microsoft Excel 2007 formatted file into my application. I found on another thread in another forum that I needed to install the 2007 Office System Driver:...
0
by: satenova | last post by:
Hello Friends, I am newbie when it comes to vb.net and i need to import excel sheet into access db using vb.net application. Here is the code i use for now to upload excel sheet and it works...
3
by: PW | last post by:
Does the worksheet have to be exported to a CSV file first or can Access import directly from an Excel workbook (.xls)? Thanks, -paulw
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
2
by: vikassawant | last post by:
hi, It's very crazy problem.I want to import excel sheet data in to JTable but I can't find any solution. Actually what I want,suppose there are 7 rows and 5 columns in a table.If I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.