Getting RunTime Error 1004 Excel Cannot Access File (1 Viewer)

bconner

Registered User.
Local time
Today, 00:25
Joined
Dec 22, 2008
Messages
183
Below is the code I am using. I am trying to create a workbook and export queries to the workbook but I am getting an error stating several possible reasons:
1. Path doesn't exsist
2. File is being used by another program
3. Work book I am trying to use has the same name as an open workbook.

I don't currently have a workbook with that name, I am letting the macro below create one and then close it and send the queries to it. I am using this code in another database and it works like a charm. When I step into the code it highlights the following section of code:
Code:
xlbook.SaveAs ("C:\Documents and Settings\Desktop\ATB Review" & GrpNum & "ATBReview.xls")


Code:
Function ATB_Analysis()
Dim GrpNum As String
Dim xlapp As Object
Dim xlbook As Object
' Module Create By Brian Conner 6/2/2009

GrpNum = Form_FrmGroupNumber.Text0.Value
     
Set xlapp = CreateObject("Excel.Application")
Set xlbook = xlapp.workbooks.Add
xlbook.SaveAs ("C:\Documents and Settings\Desktop\ATB Review" & GrpNum & "ATBReview.xls")
xlbook.Close

'Export ATB Review Reports to Excel Workbook on Desktop
DoCmd.TransferSpreadsheet acExport, , "Rej_Detail", "c:\Documents and Settings\Desktop\" & GrpNum & "ATBReview.xls"
DoCmd.TransferSpreadsheet acExport, , "Unresponded_Detail", "c:\Documents and Settings\Desktop\" & GrpNum & "ATBReview.xls"
DoCmd.TransferSpreadsheet acExport, , "CPC Non Contracted", "c:\Documents and Settings\Desktop\" & GrpNum & "ATBReview.xls"
DoCmd.TransferSpreadsheet acExport, , "*4 Appeals", "c:\Documents and Settings\Desktop\" & GrpNum & "ATBReview.xls"
DoCmd.TransferSpreadsheet acExport, , "*5 616 FSC", "c:\Documents and Settings\Desktop\" & GrpNum & "ATBReview.xls"
DoCmd.TransferSpreadsheet acExport, , "*5 FSC 616 Summary", "c:\Documents and Settings\Desktop\" & GrpNum & "ATBReview.xls"
DoCmd.TransferSpreadsheet acExport, , "*6 B7 Cerdentialing", "c:\Documents and Settings\Desktop\" & GrpNum & "ATBReview.xls"
DoCmd.TransferSpreadsheet acExport, , "*6 B7 Cerdentialing Summary", "c:\Documents and Settings\Desktop\" & GrpNum & "ATBReview.xls"
DoCmd.TransferSpreadsheet acExport, , "*9 Credit Report", "c:\Documents and Settings\Desktop\" & GrpNum & "ATBReview.xls"
 
 
 
    
     
End Function
 

namliam

The Mailman - AWF VIP
Local time
Today, 07:25
Joined
Aug 11, 2003
Messages
11,695
Brian,

Why create the (empty) workbook in the first case? I think just using transferspreadsheet, creates and appends the sheets to the workbook...

One potential problem I can see, Excel doesnt always like * in the tab names... But that should not be the problem your combatting now.... I think...
 

SOS

Registered Lunatic
Local time
Yesterday, 22:25
Joined
Aug 27, 2008
Messages
3,517
This path is invalid:

xlbook.SaveAs ("C:\Documents and Settings\Desktop\ATB Review" & GrpNum & "ATBReview.xls")

You need the USER NAME between DOCUMENTS AND SETTINGS and DESKTOP


xlbook.SaveAs ("C:\Documents and Settings\USERNAMEHERE\Desktop\ATB Review" & GrpNum & "ATBReview.xls")
 

bconner

Registered User.
Local time
Today, 00:25
Joined
Dec 22, 2008
Messages
183
Thank you for your replies, I added the Username in the Path string and it worked! Again many thanks, I don't know what I'd do without this site......
 

namliam

The Mailman - AWF VIP
Local time
Today, 07:25
Joined
Aug 11, 2003
Messages
11,695
Still I dont see the need to create the workbook first? Access' Transferspreadsheet takes care of that for you...
 

Users who are viewing this thread

Top Bottom