Solved

Transferspreadsheet 31519 error

Posted on 2014-02-27
12
579 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
12 Comments
 
LVL 38

Expert Comment

by:Jim P.
Comment Utility
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
Comment Utility
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.
Comment Utility
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
 

Author Comment

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

Expert Comment

by:Jim P.
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 38

Expert Comment

by:Jim P.
Comment Utility
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 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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 84
Comment Utility
<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
Comment Utility
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 300 total points
Comment Utility
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
Comment Utility
thanks for your help!
je
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now