Advertisement

05.24.2008 at 01:01AM PDT, ID: 23429561
[x]
Attachment Details

Using Workbook.SaveAs in Access with VBA generates Error 1004???

Asked by etsherman in Microsoft Access Database, Microsoft Excel Spreadsheet Software

Tags: , ,

I have a workbook that's generated form a website and needs to be imported into Access 2000.  However the workbook is created, Access will not import it with a message something like "incorrect format, etc.).  But, if I manually open the worksheet and save it as a M/S Excel 97-2000 workbook then Access can import it.  Therefore, in VBA code all I need to do is open the workbook and save it as FileFormat xlExcel8.

The code below produces the run-time error 1004  "SaveAs method of workbook class failed" on the
 XLObj.ActiveWorkbook.SaveAs  line.

Function FixFile()
Dim XLObj As Object

Set XLObj = CreateObject("Excel.Application")
XLObj.Workbooks.Open ("T:\TTData\Report.xls")
 
'Check to see if the workbook is read only
If XLObj.Workbooks("Report.xls").ReadOnly = True Then
    MsgBox "The Workbook is Read-Only and cannot be imported until closed, Import Cancelled!!!", vbCritical, "Import Error"
    XLObj.Quit
    Set XLObj = Nothing
    Exit Function
Else
    XLObj.DisplayAlerts = False
    XLObj.ActiveWorkbook.SaveAs FileName:="T:\TTData\Report.xls", FileFormat:=xlExcel8
    XLObj.Quit              
    Set XLObj = Nothing    
End If

End Function


Any ideas will be appreciated.

Thanks,

ETStart Free Trial
[+][-]05.24.2008 at 01:05AM PDT, ID: 21638227

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 01:07AM PDT, ID: 21638232

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 01:14AM PDT, ID: 21638247

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 01:20AM PDT, ID: 21638256

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 01:50AM PDT, ID: 21638340

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Access Database, Microsoft Excel Spreadsheet Software
Tags: Microsoft, Office, 2000
Sign Up Now!
Solution Provided By: zorvek
Participating Experts: 1
Solution Grade: B
 
 
[+][-]05.24.2008 at 02:35AM PDT, ID: 21638453

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628