Solved

Convert .xls to .mdb

Posted on 2009-07-01
3
827 Views
Last Modified: 2012-05-07
Hi Experts,
  Anyway we can convert .xls file to .mdbfile ?
0
Comment
Question by:mkdev2009
3 Comments
 
LVL 23

Accepted Solution

by:
Eirman earned 250 total points
ID: 24752959
Assuming you have access ... File > Get external Data > Import ... Then choose "Files of type" XLS
0
 
LVL 3

Assisted Solution

by:Michal-Drozd
Michal-Drozd earned 250 total points
ID: 24753562
Here is one of soultions:
Create the access application object. Open a database (or create new one).
After that you can execute any you want that you can normally do from code in access

Dim oApp As Object
Set oApp = CreateObject("Access.Application")
oApp.Visible= True ' if you want to see it

read up on the following:
OpenDatabase (dbname, options, read-only, connect)

look at:
TransferText(TransferType, SpecificationName, TableName, FileName, HasFieldNames, HTMLTableName, CodePage)
more about this function you find here: http://www.blueclaw-db.com/transfertext-docmd.htm

or better this function (xls to mdb) something like this:
docmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "TMP_TABLE", "c:\my_file.xls", true, "WorksheetName"

Change the True to False if the first row does not contain column headings
example, like so with oApp:
oApp.DoCmd.TransferText( .....enter args)

don't forget when done to:
oApp.quit
Set oApp = Nothing

small example:
Private Sub cmdImport_Click()
Dim strFileName As String ' filename we are importing from
 
'get filename from user to import
If strFileName = "" Then
With ComDlg
.CancelError = True
.Filter = "XLS Files (*.xls)|*.xls" _
& "|All Files (*.*)|*.*"
.DefaultExt = ".ext"
.DialogTitle = "Select File"
.FilterIndex = 1
'.InitDir = "default directory goes here"
.Flags = cdlOFNHideReadOnly
.ShowOpen
If .FileName <> "" Then strFileName = .FileName
End With
End If
 
'do import of file
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "ImportTable", strFileName, True, "ImportArea"
Exit_cmdImport_Click:
Exit Sub

Open in new window

0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question