Skip Bisconer
Who Me?
- Local time
- Today, 15:48
- Joined
- Jan 22, 2008
- Messages
- 285
I am using this code to write to an .xlsx file and when it opens it opens in ReaD Only. Can some one give me a cure for this?
Code:
Function ExportToExcel()
Dim objXL As Object
Dim xlWB As Object
Dim xlWS As Object
Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
Set xlWB = objXL.Workbooks.Open("C:\Amex\Bisconer.xlsx")
Set xlWS = xlWB.Worksheets("CurrentCharges11152")
Dim db As Database
Dim rs As Recordset
Dim i As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("CurrentCharges11152", , dbOpenDynamic)
rs.MoveFirst
i = 1
Do Until rs.EOF
With xlWS
' assign records to specific cells
.Range("A" & i + 1).Value = rs.Fields("LastName").Value
.Range("B" & i + 1).Value = rs.Fields("FirstName").Value
.Range("C" & i + 1).Value = rs.Fields("CardNumber").Value
.Range("D" & i + 1).Value = rs.Fields("Date").Value
.Range("E" & i + 1).Value = rs.Fields("Commodity").Value
.Range("F" & i + 1).Value = rs.Fields("BusinessType").Value
.Range("G" & i + 1).Value = rs.Fields("SupplierName").Value
.Range("H" & i + 1).Value = rs.Fields("Amount").Value
.Range("I" & i + 1).Value = rs.Fields("BusinessPurpose").Value
.Range("J" & i + 1).Value = rs.Fields("Customer").Value
End With
i = i + 1
rs.MoveNext
Loop
End Function