Arghhhh… this is driving me crazy. Not sure whether to post this under Excel or Access.
Some VBA code from Access 97 controlling Excel 97 was working, and now it stoppped and I can’t figure out why. The VBA code determines which columns of the spreadsheet to delete, stores the results in a variable named sRows (sorry…), and calls the Delete method. The error message is code #1004 – “Method columns of object ‘_Application’ failed.
What is really frustrating is that if I delete any random column manually from Excel while in debug mode, then the code works just fine. I’ve tried rebooting the computer to no avail.
Here are the relevant sections of code in the Access form:
Private Sub ModifyLODMxl(objXL As Excel.Application, rs As DAO.Recordset, sWkbk As String)
Dim sRows As String
Dim iRow As Integer
Dim nTank as Integer
With objXL
[lines snipped…]
‘ this section mentions ROWS, but it is really COLUMNS
.Worksheets(“Dip History”).Activate
i = Int((nTank * 3 + 2) / 26)
If i = 0 Then
sRows = “”
Else
sRows = Chr(64 + i)
End If
i = (nTank * 3 + 2) – (i * 26) + 1
sRows = sRows & Chr(64 + i) & “:CL”
‘ at this point, sRows has the value “R:CL”
.Columns(sRows).Delete Shift:=xlToLeft ‘ <<<< error 1004 occurrs here
If I go into the Access Immediate window, and type, objXL.Columns("DD").Delete then I get the same error message. Switch into Excel and delete a random column manually, then back to Access and reissue the command from the Immediate window, and it works fine.
Can anybody see what I am overlooking or suggest a workaround.