Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm running Excel from Access 2003. The following code runs without error
when I create the Excel csv file on my local computer. But when I create the Excel csv file on the Network, I get an error on this line: Set xlWbDet = xlAppDet.workbooks.Add Here is the relevant code: Dim xlAppMst As Object Dim xlWbMst As Object Dim IStartedXL As Boolean Dim i As Integer, iCount As Integer On Error Resume Next Set xlAppMst = GetObject(, "Excel.Application") On Error GoTo 0 If xlAppMst Is Nothing Then Set xlAppMst = CreateObject("Excel.Application") IStartedXL = True End If Set xlWbMst = xlAppMst.workbooks.Add xlAppMst.Range("A1:AA3000").NumberFormat = "@" 'xlWbMst.SaveAs fNameMst '---Access Dim rsCSVmst As DAO.Recordset Set rsCSVmst = db.OpenRecordset("qtmpMasterCSV") iCount = rsCSVmst.Fields.Count '--- xlAppMst.Range("A1").Select For i = 0 To iCount - 1 xlAppMst.Cells(1, i + 1).Value = rsCSVmst.Fields(i).Name Next i i = 0 xlAppMst.Range("A2").CopyFromRecordset rsCSVmst xlWbMst.SaveAs fNameMst xlWbMst.Close False If IStartedXL Then xlAppMst.Quit Set xlWbMst = Nothing Set xlAppMst = Nothing rsCSVmst.Close Set rsCSVmst = Nothing 'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD Dim xlAppDet As Object Dim xlWbDet As Object On Error Resume Next Set xlAppDet = GetObject(, "Excel.Application") On Error GoTo 0 If xlAppDet Is Nothing Then Set xlAppDet = CreateObject("Excel.Application") IStartedXL = True End If Set xlWbDet = xlAppDet.workbooks.Add '<---AUTOMATION ERROR HERE xlAppDet.Range("A1:AA3000").NumberFormat = "@" '---Access Dim rsCSVDet As DAO.Recordset Set rsCSVDet = db.OpenRecordset("qtmpDetailCSV") iCount = rsCSVDet.Fields.Count '--- xlAppDet.Range("A1").Select For i = 0 To iCount - 1 xlAppDet.Cells(1, i + 1).Value = rsCSVDet.Fields(i).Name Next i i = 0 xlAppDet.Range("A2").CopyFromRecordset rsCSVDet xlWbDet.SaveAs fNameDet xlWbDet.Close False If IStartedXL Then xlAppDet.Quit Set xlWbDet = Nothing Set xlAppDet = Nothing What would cause this? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I should have added that I don't get the error on Excel is running. I only get it when Excel is not running. "Perico" wrote: I'm running Excel from Access 2003. The following code runs without error when I create the Excel csv file on my local computer. But when I create the Excel csv file on the Network, I get an error on this line: Set xlWbDet = xlAppDet.workbooks.Add Here is the relevant code: Dim xlAppMst As Object Dim xlWbMst As Object Dim IStartedXL As Boolean Dim i As Integer, iCount As Integer On Error Resume Next Set xlAppMst = GetObject(, "Excel.Application") On Error GoTo 0 If xlAppMst Is Nothing Then Set xlAppMst = CreateObject("Excel.Application") IStartedXL = True End If Set xlWbMst = xlAppMst.workbooks.Add xlAppMst.Range("A1:AA3000").NumberFormat = "@" 'xlWbMst.SaveAs fNameMst '---Access Dim rsCSVmst As DAO.Recordset Set rsCSVmst = db.OpenRecordset("qtmpMasterCSV") iCount = rsCSVmst.Fields.Count '--- xlAppMst.Range("A1").Select For i = 0 To iCount - 1 xlAppMst.Cells(1, i + 1).Value = rsCSVmst.Fields(i).Name Next i i = 0 xlAppMst.Range("A2").CopyFromRecordset rsCSVmst xlWbMst.SaveAs fNameMst xlWbMst.Close False If IStartedXL Then xlAppMst.Quit Set xlWbMst = Nothing Set xlAppMst = Nothing rsCSVmst.Close Set rsCSVmst = Nothing 'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD Dim xlAppDet As Object Dim xlWbDet As Object On Error Resume Next Set xlAppDet = GetObject(, "Excel.Application") On Error GoTo 0 If xlAppDet Is Nothing Then Set xlAppDet = CreateObject("Excel.Application") IStartedXL = True End If Set xlWbDet = xlAppDet.workbooks.Add '<---AUTOMATION ERROR HERE xlAppDet.Range("A1:AA3000").NumberFormat = "@" '---Access Dim rsCSVDet As DAO.Recordset Set rsCSVDet = db.OpenRecordset("qtmpDetailCSV") iCount = rsCSVDet.Fields.Count '--- xlAppDet.Range("A1").Select For i = 0 To iCount - 1 xlAppDet.Cells(1, i + 1).Value = rsCSVDet.Fields(i).Name Next i i = 0 xlAppDet.Range("A2").CopyFromRecordset rsCSVDet xlWbDet.SaveAs fNameDet xlWbDet.Close False If IStartedXL Then xlAppDet.Quit Set xlWbDet = Nothing Set xlAppDet = Nothing What would cause this? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I may have cured this problem by using a message box to permit, in effect
pause, the first automation routine to complete before inaugerating the second automation routine. "Perico" wrote: I should have added that I don't get the error on Excel is running. I only get it when Excel is not running. "Perico" wrote: I'm running Excel from Access 2003. The following code runs without error when I create the Excel csv file on my local computer. But when I create the Excel csv file on the Network, I get an error on this line: Set xlWbDet = xlAppDet.workbooks.Add Here is the relevant code: Dim xlAppMst As Object Dim xlWbMst As Object Dim IStartedXL As Boolean Dim i As Integer, iCount As Integer On Error Resume Next Set xlAppMst = GetObject(, "Excel.Application") On Error GoTo 0 If xlAppMst Is Nothing Then Set xlAppMst = CreateObject("Excel.Application") IStartedXL = True End If Set xlWbMst = xlAppMst.workbooks.Add xlAppMst.Range("A1:AA3000").NumberFormat = "@" 'xlWbMst.SaveAs fNameMst '---Access Dim rsCSVmst As DAO.Recordset Set rsCSVmst = db.OpenRecordset("qtmpMasterCSV") iCount = rsCSVmst.Fields.Count '--- xlAppMst.Range("A1").Select For i = 0 To iCount - 1 xlAppMst.Cells(1, i + 1).Value = rsCSVmst.Fields(i).Name Next i i = 0 xlAppMst.Range("A2").CopyFromRecordset rsCSVmst xlWbMst.SaveAs fNameMst xlWbMst.Close False If IStartedXL Then xlAppMst.Quit Set xlWbMst = Nothing Set xlAppMst = Nothing rsCSVmst.Close Set rsCSVmst = Nothing 'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD Dim xlAppDet As Object Dim xlWbDet As Object On Error Resume Next Set xlAppDet = GetObject(, "Excel.Application") On Error GoTo 0 If xlAppDet Is Nothing Then Set xlAppDet = CreateObject("Excel.Application") IStartedXL = True End If Set xlWbDet = xlAppDet.workbooks.Add '<---AUTOMATION ERROR HERE xlAppDet.Range("A1:AA3000").NumberFormat = "@" '---Access Dim rsCSVDet As DAO.Recordset Set rsCSVDet = db.OpenRecordset("qtmpDetailCSV") iCount = rsCSVDet.Fields.Count '--- xlAppDet.Range("A1").Select For i = 0 To iCount - 1 xlAppDet.Cells(1, i + 1).Value = rsCSVDet.Fields(i).Name Next i i = 0 xlAppDet.Range("A2").CopyFromRecordset rsCSVDet xlWbDet.SaveAs fNameDet xlWbDet.Close False If IStartedXL Then xlAppDet.Quit Set xlWbDet = Nothing Set xlAppDet = Nothing What would cause this? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
excel 2003 file converted to .xlsm file when save to network drive | Excel Discussion (Misc queries) | |||
Error Trapping saving file to network drive | Excel Programming | |||
Automation Error: The system cannot find file specified | Excel Programming | |||
Automation Error in Excel VBA | Excel Programming | |||
VB Excel Automation Error | Excel Programming |