Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Transferspreadsheet 31519 error

Posted on 2014-02-27
12
Medium Priority
?
649 Views
Last Modified: 2014-04-25
I am trying to import an Excel .xlsx file into Access using VB code and receive a 31519 error ("You can not import this file") followed by error 424 ("Object required")

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "table name", GetFile, True

GetFile = the Excel file name

What am I missing?

thanks for your help
je
0
Comment
Question by:aeolianje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 38

Expert Comment

by:Jim P.
ID: 39892600
Per the AcSpreadSheetType Enumeration the  acSpreadsheetTypeExcel9 is the Microsoft Excel 2000 format. The .xlsx is a 2007 or above extension.

Then what version of Access and what version of the DB are you doing this in?

And is the GetFile the full path like "C:\Full\Path\File.xslx" or just  "File.xslx"?
0
 

Author Comment

by:aeolianje
ID: 39892736
Access 2010
The GetFile code works in another app...

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "tablename", GetFile, True

I tried acSpreadsheetTypeExcel9 to see if that made a difference -- but still get the same error with 9 and 12 in the new app -- same code.  So it's odd that it woks in one place and not another.

I have a similar function that imports .csv text file and have no issues.

thanks again for the help
je
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39892872
What is the source for the SS?

One I ran into was that my CRM would export the query results as a file with an .xls extension. It would open fine in in Excel, but a straight import into Access would fail.

It took forever to figure it out. Then I opened the file with a text editor instead and it turned out to be an XML file with an Excel header string. Excel did the conversion -- but Access couldn't understand it.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aeolianje
ID: 39892955
I am tring to IMPORT -- not export... ?
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39892985
I understand you want to import.

I'm saying what is the Excel SS source? Is it a website or something similar? Are you sure it is a true Excel file that has been edited by Excel?
0
 

Author Comment

by:aeolianje
ID: 39893113
Yes... Sorry I misunderstood your question

I am able to open it in Excel.  It has a .xlsx extension.

What else should I be looking for? Thanks
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39893180
Even though it has an xlsx until you actually edit and save the file it may still be XML file under the covers. Right click the file and do an Open With and select Notepad and see what it looks like in the guts.
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39897140
As Jim P mentioned, and I think you indicated, it may show up as xlsx but have XML "under the covers".  If you preceed your Transferspreadsheet with a segment of code that actually opens the Excel workbook using automation and then does a SaveAs with an xlsx file, you may find that you are able to read it properly with TransferSpreadsheet.

Give it a try by doing it manually.
0
 
LVL 85
ID: 39898407
<no points please>

I too have had issues with files that pretend to be xls or xlsx files, especially those that come down from internet portals. One of my clients downloads a file every day from their vendor portal, and uses a utility I created to import that file into their database. They ALWAYS review the file before importing, so I don't automatically SaveAs in my code, but instead have instructed them to do so.

About once a month I get an email saying the utility won't work. About an hour after that, I get an email saying that they forgot to do the SaveAs portion of the process ...
0
 

Author Comment

by:aeolianje
ID: 40013050
I am able to import the xls file manually - but get the 31519 error when trying to use the transferspreadsheet vba.

I managed to get around it by saving the .xls as a .csv file -- and the transfertext option works.

Thanks for all your input.

Do you know of any automated way to save .xls files to .cvs?

je
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 1200 total points
ID: 40013267
Because I know the file I'm importing from is going to be an HTML/XML file I came up with this code to convert it to a true XLS file.

Public Function OpenHtmNSaveXL(htmFile As String, xlFile As String)
Dim xlObj As Object
Set xlObj = CreateObject("excel.application")
    xlObj.DisplayAlerts = False
    xlObj.Workbooks.Open htmFile
    xlObj.ActiveWorkbook.SaveAs xlFile, xlWorkbookNormal
    xlObj.Quit
    Set xlObj = Nothing

End Function

Open in new window


It is just changing the SaveAs xlFile to SaveAs xlcsv. But I'm not sure it will open an HTML/XML file correctly.
0
 

Author Closing Comment

by:aeolianje
ID: 40023459
thanks for your help!
je
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

604 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