P
Pendragon
Access03/WinXP
(Probems with initial post - my apologies if this is duplicated)
I am using what seems to be a standard process to export a query to Excel.
The code below is the first part of an IF...THEN where it is true that Excel
is open.
Excel is open and other workbooks are open. I need this part of the code to
write the data to Excel and then close the workbook but leave open Excel and
the other workbooks. The current workbook (the exported data) is not being
closed.
Dim I As Long
Dim objExcel As Excel.Application
stDocName = "c:\datafiles\qryClassRegistrations.xls"
If fIsAppRunning("Excel") Then
Set objExcel = GetObject(, "Excel.Application")
booXL = False
If fIsFileOpen(stDocName) = True Then
With objExcel
.Workbooks(1).Close False, , False
End With
End If
If fIsFileDIR(stDocName, 1) = -1 Then
Kill stDocName
End If
With objExcel
.Workbooks.Add
.ActiveSheet.Name = CStr("Registrations")
For I = 0 To rsExport.Fields.Count - 1
.cells(1, I + 1) = "'" & rsExport.Fields(I).Name
Next I
.Range(.cells(1, 1), .cells(1, rsExport.Fields.Count)).Font.Bold =
True
.Range(.cells(1, 1), .cells(1, rsExport.Fields.Count)).Columns.AutoFit
.selection.Range("A2").CopyFromRecordset rsExport
.Workbooks(1).SaveAs stDocName
.Workbooks(1).Close False, , False
End With
ELSE
.......
The line .Workbooks(1).Close False,,False is not closing the active workbook
qryClassRegistrations.xls.
Any help is much appreciated!!
(Probems with initial post - my apologies if this is duplicated)
I am using what seems to be a standard process to export a query to Excel.
The code below is the first part of an IF...THEN where it is true that Excel
is open.
Excel is open and other workbooks are open. I need this part of the code to
write the data to Excel and then close the workbook but leave open Excel and
the other workbooks. The current workbook (the exported data) is not being
closed.
Dim I As Long
Dim objExcel As Excel.Application
stDocName = "c:\datafiles\qryClassRegistrations.xls"
If fIsAppRunning("Excel") Then
Set objExcel = GetObject(, "Excel.Application")
booXL = False
If fIsFileOpen(stDocName) = True Then
With objExcel
.Workbooks(1).Close False, , False
End With
End If
If fIsFileDIR(stDocName, 1) = -1 Then
Kill stDocName
End If
With objExcel
.Workbooks.Add
.ActiveSheet.Name = CStr("Registrations")
For I = 0 To rsExport.Fields.Count - 1
.cells(1, I + 1) = "'" & rsExport.Fields(I).Name
Next I
.Range(.cells(1, 1), .cells(1, rsExport.Fields.Count)).Font.Bold =
True
.Range(.cells(1, 1), .cells(1, rsExport.Fields.Count)).Columns.AutoFit
.selection.Range("A2").CopyFromRecordset rsExport
.Workbooks(1).SaveAs stDocName
.Workbooks(1).Close False, , False
End With
ELSE
.......
The line .Workbooks(1).Close False,,False is not closing the active workbook
qryClassRegistrations.xls.
Any help is much appreciated!!