Ken,
Sorry for the brain fart but the error code 429 is exactly
what we should see if we use GetObject when Excel is not
opened (that's why we Resume Next). So no problem there.
However, I got the code to run but the .quit method is
still not closing Excel in the background.
Here's my entire subroutine (thanks for any additionl
help):
Private Sub psFormatTextFields()
'For Excess and Umbrella, format all Cert ID # and
Underlyer NAIC code fields as text. This is to
'prevent Numeric overload errors.
Dim objXLApp As Object
Dim objXLBook As Object
Dim intCtr As Integer
Dim ExcelAlreadyOpen As Boolean
Dim varX As Variant
Dim lngMeterCtr As Long
On Error Resume Next
Set objXLApp = GetObject(, "Excel.Application")
If Err.number <> 0 Then
Err.Clear
Set objXLApp = CreateObject("Excel.Application")
ExcelAlreadyOpen = False
Else
ExcelAlreadyOpen = True
End If
'Set objXLBook = objXLApp.Workbooks(mState.strFilePath)
Set objXLBook = GetObject(mState.strFilePath)
' Make sure both Excel and the workbook are visible (they
won't
' be if Excel was launched by our Automation request)
'objXLApp.Visible = true
'objXLBook.Windows(1).Visible = true
With objXLBook.Worksheets(1)
varX = SysCmd(acSysCmdInitMeter, "Formatting
spreadsheet ", .UsedRange.Rows.Count)
intCtr = 2 'start at 2nd row of spreadsheet to avoid
headers.
Do Until intCtr = .UsedRange.Rows.Count + 1
lngMeterCtr = lngMeterCtr + 1
varX = SysCmd(acSysCmdUpdateMeter, lngMeterCtr)
'Cert ID #
.Range("AB" & intCtr).Value = " " & .Range("AB" &
intCtr).Value
.Range("AB" & intCtr).Value = Right(.Range("AB" &
intCtr).Value, Len(.Range("AB" & intCtr).Value) - 1)
'Underlyer GL NAIC
.Range("AX" & intCtr).Value = " " & .Range("AX" &
intCtr).Value
.Range("AX" & intCtr).Value = Right(.Range("AX" &
intCtr).Value, Len(.Range("AX" & intCtr).Value) - 1)
'Underlyer Auto NAIC
.Range("BA" & intCtr).Value = " " & .Range("BA" &
intCtr).Value
.Range("BA" & intCtr).Value = Right(.Range("BA" &
intCtr).Value, Len(.Range("BA" & intCtr).Value) - 1)
'Underlyer Emp Liability NAIC
.Range("BL" & intCtr).Value = " " & .Range("BL" &
intCtr).Value
.Range("BL" & intCtr).Value = Right(.Range("BL" &
intCtr).Value, Len(.Range("BL" & intCtr).Value) - 1)
'Underlyer Other 1 NAIC
.Range("BP" & intCtr).Value = " " & .Range("BP" &
intCtr).Value
.Range("BP" & intCtr).Value = Right(.Range("BP" &
intCtr).Value, Len(.Range("BP" & intCtr).Value) - 1)
'Underlyer Other 2 NAIC
.Range("BT" & intCtr).Value = " " & .Range("BT" &
intCtr).Value
.Range("BT" & intCtr).Value = Right(.Range("BT" &
intCtr).Value, Len(.Range("BT" & intCtr).Value) - 1)
intCtr = intCtr + 1
Loop
End With
objXLBook.Windows(1).Visible = True
objXLBook.Save
objXLBook.Close
Set objXLBook = Nothing
If ExcelAlreadyOpen = False Then
'just close workbook
objXLApp.Quit
End If
Set objXLApp = Nothing
End Sub