PRMiller2
Technical User
- Jul 30, 2010
- 123
Feel like I'm asking for a lot of help lately! I have a procedure that is being called to parse through Excel files. It works fine when one Excel file is passed to the procedure. It also works fine when the procedure is called multiple times (ie a loop that calls the procedure, passing a workbook name, then calling the procedure again and passing a second workbook name, etc), but only in debug mode. At runtime, I receive "Error 91: Object variable or With block variable not set."
Here's the code:
As you can see, I've entered a number of "DoEvents" statements, hoping the processor just needed to catch up. That doesn't seem to have done the trick.
At debug, the code errors out on the line "Set appExcel = GetExcelApp()".
Thanks in advance!
Here's the code:
Code:
Public Function EditExcel(ByVal strFileName As String)
On Error GoTo Err_Handler
Dim appExcel As Excel.Application
DoEvents
Set appExcel = GetExcelApp()
appExcel.Workbooks.Open strFileName
appExcel.Visible = False
DoEvents
With appExcel.Sheets(1)
If .Range("A1").value = "Super Pharmacy" Then
appExcel.Worksheets(1).Rows(1).Delete
.Range("A1").value = "SuperPharmacyNetworkID"
.Range("B1").value = "RxNetworkID"
.Range("C1").value = "ResolvedSrvProvID"
.Range("D1").value = "PharmacyNme"
.Range("E1").value = "AFFRelationshipID"
.Range("F1").value = "CarrierID"
.Range("G1").value = "AccountID"
.Range("H1").value = "GroupID"
.Range("I1").value = "TCDMemberID"
.Range("J1").value = "RxClaimNum"
.Range("K1").value = "ClaimSeqNbr"
.Range("L1").value = "SbmRxNumber"
.Range("M1").value = "SbmDteFilled"
.Range("N1").value = "DateSubmitted"
.Range("O1").value = "SbmDaysSupply"
.Range("P1").value = "TCDSbmQtyDispensed"
.Range("Q1").value = "SbmProductSelectionCde"
.Range("R1").value = "MultiSrcCode"
.Range("S1").value = "GenericIndOverride"
.Range("T1").value = "SbmCompoundCde"
.Range("U1").value = "TCDSbmProductIDQual"
.Range("V1").value = "TCDSbmProductID"
.Range("W1").value = "PRDDescriptionAbbrev"
.Range("X1").value = "GPINumber"
.Range("Y1").value = "PDTPhrCostTypeCde"
.Range("Z1").value = "PDTPhrPriceType"
.Range("AA1").value = "CostTypePerUnitCost"
.Range("AB1").value = "TCDSbmIngredientCst"
.Range("AC1").value = "TCDSbmDispensingFee"
.Range("AD1").value = "SBMTotalSalesTax"
.Range("AE1").value = "TCDSbmGrossAmtDue"
.Range("AF1").value = "TCDSbmUsualAndCustomary"
.Range("AG1").value = "AverageWholesaleUnitPr"
.Range("AH1").value = "PDTCalPhrIngredCost"
.Range("AI1").value = "PDTCalPhrDispFee"
.Range("AJ1").value = "CalPhrTotSalesTax"
.Range("AK1").value = "PDTCalPhrPatPayAmt"
.Range("AL1").value = "PDTCalPhrTotalAmtDue"
.Range("AM1").value = "PDTPhrIngredientCost"
.Range("AN1").value = "PDTPhrDispensingFee"
.Range("AO1").value = "PhrTotalSalesTax"
.Range("AP1").value = "PDTPhrTotalPatPayAmt"
.Range("AQ1").value = "PDTPhrTotalAmountDue"
.Range("AR1").value = "PDTPhrWithholdAmount"
.Range("AS1").value = "FinalPlanCde"
.Range("AT1").value = "TCDClaimStatus"
.Range("AU1").value = "PDTPharPriceSchedName"
.Range("AV1").value = "PharmacyPriceTableName"
.Range("AW1").value = "PD3PhrDrgCostSchedID"
.Range("AX1").value = "PD3PhrDrgCstCompSchd"
.Range("AY1").value = "PDTPharPatientSchdNme"
.Range("AZ1").value = "PharmacyPatSchedTable"
.Range("BA1").value = "PDTPharFeeSchedNme"
.Range("BB1").value = "PDTPhrIncentiveAmount"
.Range("BC1").value = "PDTPharTaxSchedName"
.Range("BD1").value = "PharmacyNetworkNDCList"
.Range("BE1").value = "PharmacyNetworkGPIList"
.Range("BF1").value = "PlanGPIListName"
.Range("BG1").value = "PlanNDCListName"
.Range("BH1").value = "TC3ProdPreferredLstID"
.Range("BI1").value = "SbmPriorAuthMedCerCd"
.Range("BJ1").value = "PAMCNBR"
.Range("BK1").value = "SpecialtyPgm"
.Range("BL1").value = "SpecialtyInd"
.Range("BM1").value = "SpecialtySched"
End If
appExcel.ActiveWorkbook.Save
DoEvents
End With
appExcel.ActiveWorkbook.Saved = True
DoEvents
appExcel.Workbooks.Close
DoEvents
appExcel.Quit
Set appExcel = Nothing
Debug.Print strFileName
EditExcel = 1
Exit_Handler:
Exit Function
Err_Handler:
If Err.Number = 1004 Then
MsgBox "Please close Excel before continuing.", vbOKOnly + vbExclamation, "Prime Mail Audit"
EditExcel = 0
Else
Call LogError(Err.Number, Err.Description, "frmProcessAudit.EditExcel()")
End If
Resume Exit_Handler
End Function
As you can see, I've entered a number of "DoEvents" statements, hoping the processor just needed to catch up. That doesn't seem to have done the trick.
At debug, the code errors out on the line "Set appExcel = GetExcelApp()".
Thanks in advance!