问题已经解决,在引用excel对象前执行一次 excelApps:=unAssigned; 就不会出错,菜鸟问的问题也菜,让
各位见笑了;采用 comObj,有不少好处,但是,不能直接引用类型库中定义的常量,如不能引用xlWBATWorksheet,
而只能是-4167,下面是一个对应表(是我下载的一个源程序中带的,各大家共享,高手就不必管它啦:)
const
{XlPageOrientation}
xlLandscape = 2;
xlPortrait = 1;
{XlPaperSize}
xlPaper10x14 = 16;
xlPaper11x17 = 17;
xlPaperA3 = 8;
xlPaperA4 = 9;
xlPaperA4Small = 10;
xlPaperA5 = 11;
xlPaperB4 = 12;
xlPaperB5 = 13;
xlPaperCsheet = 24;
xlPaperDsheet = 25;
xlPaperEnvelope10 = 20;
xlPaperEnvelope11 = 21;
xlPaperEnvelope12 = 22;
xlPaperEnvelope14 = 23;
xlPaperEnvelope9 = 19;
xlPaperEnvelopeB4 = 33;
xlPaperEnvelopeB5 = 34;
xlPaperEnvelopeB6 = 35;
xlPaperEnvelopeC3 = 29;
xlPaperEnvelopeC4 = 30;
xlPaperEnvelopeC5 = 28;
xlPaperEnvelopeC6 = 31;
xlPaperEnvelopeC65 = 32;
xlPaperEnvelopeDL = 27;
xlPaperEnvelopeItaly = 36;
xlPaperEnvelopeMonarch = 37;
xlPaperEnvelopePersonal = 38;
xlPaperEsheet = 26;
xlPaperExecutive = 7;
xlPaperFanfoldLegalGerman = 41;
xlPaperFanfoldStdGerman = 40;
xlPaperFanfoldUS = 39;
xlPaperFolio = 14;
xlPaperLedger = 4;
xlPaperLegal = 5;
xlPaperLetter = 1;
xlPaperLetterSmall = 2;
xlPaperNote = 18;
xlPaperQuarto = 15;
xlPaperStatement = 6;
xlPaperTabloid = 3;
xlPaperUser = 256;
{XlPasteSpecialOperation}
xlPasteSpecialOperationAdd = 2;
xlPasteSpecialOperationDivide = 5;
xlPasteSpecialOperationMultiply = 4;
xlPasteSpecialOperationNone = -4142;
xlPasteSpecialOperationSubtract = 3;
{XlPasteType}
xlPasteAll = -4104;
xlPasteAllExceptBorders = 6;
xlPasteFormats = -4122;
xlPasteFormulas = -4123;
xlPasteComments = -4144;
xlPasteValues = -4163;
{XlClipboardFormat}
xlClipboardFormatBIFF = 8;
xlClipboardFormatBIFF2 = 18;
xlClipboardFormatBIFF3 = 20;
xlClipboardFormatBIFF4 = 30;
xlClipboardFormatBinary = 15;
xlClipboardFormatBitmap = 9;
xlClipboardFormatCGM = 13;
xlClipboardFormatCSV = 5;
xlClipboardFormatDIF = 4;
xlClipboardFormatDspText = 12;
xlClipboardFormatEmbeddedObject = 21;
xlClipboardFormatEmbedSource = 22;
xlClipboardFormatLink = 11;
xlClipboardFormatLinkSource = 23;
xlClipboardFormatLinkSourceDesc = 32;
xlClipboardFormatMovie = 24;
xlClipboardFormatNative = 14;
xlClipboardFormatObjectDesc = 31;
xlClipboardFormatObjectLink = 19;
xlClipboardFormatOwnerLink = 17;
xlClipboardFormatPICT = 2;
xlClipboardFormatPrintPICT = 3;
xlClipboardFormatRTF = 7;
xlClipboardFormatScreenPICT = 29;
xlClipboardFormatStandardFont = 28;
xlClipboardFormatStandardScale = 27;
xlClipboardFormatSYLK = 6;
xlClipboardFormatTable = 16;
xlClipboardFormatText = 0;
xlClipboardFormatToolFace = 25;
xlClipboardFormatToolFacePICT = 26;
xlClipboardFormatVALU = 1;
xlClipboardFormatWK1 = 10;
xlAll = -4104;
xlAutomatic = -4105;
xlBoth = 1;
xlCenter = -4108;
xlChecker = 9;
xlCircle = 8;
xlCorner = 2;
xlCrissCross = 16;
xlCross = 4;
xlDiamond = 2;
xlDistributed = -4117;
xlDoubleAccounting = 5;
xlFixedValue = 1;
xlFormats = -4122;
xlGray16 = 17;
xlGray8 = 18;
xlGrid = 15;
xlHigh = -4127;
xlInside = 2;
xlJustify = -4130;
xlLightDown = 13;
xlLightHorizontal = 11;
xlLightUp = 14;
xlLightVertical = 12;
xlLow = -4134;
xlManual = -4135;
xlMinusValues = 3;
xlModule = -4141;
xlNextToAxis = 4;
xlNone = -4142;
xlNotes = -4144;
xlOff = -4146;
xlOn = 1;
xlPercent = 2;
xlPlus = 9;
xlPlusValues = 2;
xlSemiGray75 = 10;
xlShowLabel = 4;
xlShowLabelAndPercent = 5;
xlShowPercent = 3;
xlShowValue = 2;
xlSimple = -4154;
xlSingle = 2;
xlSingleAccounting = 4;
xlSolid = 1;
xlSquare = 1;
xlStar = 5;
xlStError = 4;
xlToolbarButton = 2;
xlTriangle = 3;
xlGray25 = -4124;
xlGray50 = -4125;
xlGray75 = -4126;
xlBottom = -4107;
xlLeft = -4131;
xlRight = -4152;
xlTop = -4160;
xl3DBar = -4099;
xl3DSurface = -4103;
xlBar = 2;
xlColumn = 3;
xlCombination = -4111;
xlCustom = -4114;
xlDefaultAutoFormat = -1;
xlMaximum = 2;
xlMinimum = 4;
xlOpaque = 3;
xlTransparent = 2;
xlBidi = -5000;
xlLatin = -5001;
xlContext = -5002;
xlLTR = -5003;
xlRTL = -5004;
xlVisualCursor = 2;
xlLogicalCursor = 1;
xlSystem = 1;
xlPartial = 3;
xlHindiNumerals = 3;
xlBidiCalendar = 3;
xlGregorian = 2;
xlComplete = 4;
xlScale = 3;
xlClosed = 3;
xlColor1 = 7;
xlColor2 = 8;
xlColor3 = 9;
xlConstants = 2;
xlContents = 2;
xlBelow = 1;
xlCascade = 7;
xlCenterAcrossSelection = 7;
xlChart4 = 2;
xlChartSeries = 17;
xlChartShort = 6;
xlChartTitles = 18;
xlClassic1 = 1;
xlClassic2 = 2;
xlClassic3 = 3;
xl3DEffects1 = 13;
xl3DEffects2 = 14;
xlAbove = 0;
xlAccounting1 = 4;
xlAccounting2 = 5;
xlAccounting3 = 6;
xlAccounting4 = 17;
xlAdd = 2;
xlDebugCodePane = 13;
xlDesktop = 9;
xlDirect = 1;
xlDivide = 5;
xlDoubleClosed = 5;
xlDoubleOpen = 4;
xlDoubleQuote = 1;
xlEntireChart = 20;
xlExcelMenus = 1;
xlExtended = 3;
xlFill = 5;
xlFirst = 0;
xlFloating = 5;
xlFormula = 5;
xlGeneral = 1;
xlGridline = 22;
xlIcons = 1;
xlImmediatePane = 12;
xlInteger = 2;
xlLast = 1;
xlLastCell = 11;
xlList1 = 10;
xlList2 = 11;
xlList3 = 12;
xlLocalFormat1 = 15;
xlLocalFormat2 = 16;
xlLong = 3;
xlLotusHelp = 2;
xlMacrosheetCell = 7;
xlMixed = 2;
xlMultiply = 4;
xlNarrow = 1;
xlNoDocuments = 3;
xlOpen = 2;
xlOutside = 3;
xlReference = 4;
xlSemiautomatic = 2;
xlShort = 1;
xlSingleQuote = 2;
xlStrict = 2;
xlSubtract = 3;
xlTextBox = 16;
xlTiled = 1;
xlTitleBar = 8;
xlToolbar = 1;
xlVisible = 12;
xlWatchPane = 11;
xlWide = 3;
xlWorkbookTab = 6;
xlWorksheet4 = 1;
xlWorksheetCell = 3;
xlWorksheetShort = 5;
xlAllExceptBorders = 6;
xlLeftToRight = 2;
xlTopToBottom = 1;
xlVeryHidden = 2;
xlDrawingObject = 14;
{XlChartType}
xlColumnClustered = 51;
xlColumnStacked = 52;
xlColumnStacked100 = 53;
xl3DColumnClustered = 54;
xl3DColumnStacked = 55;
xl3DColumnStacked100 = 56;
xlBarClustered = 57;
xlBarStacked = 58;
xlBarStacked100 = 59;
xl3DBarClustered = 60;
xl3DBarStacked = 61;
xl3DBarStacked100 = 62;
xlLineStacked = 63;
xlLineStacked100 = 64;
xlLineMarkers = 65;
xlLineMarkersStacked = 66;
xlLineMarkersStacked100 = 67;
xlPieOfPie = 68;
xlPieExploded = 69;
xl3DPieExploded = 70;
xlBarOfPie = 71;
xlXYScatterSmooth = 72;
xlXYScatterSmoothNoMarkers = 73;
xlXYScatterLines = 74;
xlXYScatterLinesNoMarkers = 75;
xlAreaStacked = 76;
xlAreaStacked100 = 77;
xl3DAreaStacked = 78;
xl3DAreaStacked100 = 79;
xlDoughnutExploded = 80;
xlRadarMarkers = 81;
xlRadarFilled = 82;
xlSurface = 83;
xlSurfaceWireframe = 84;
xlSurfaceTopView = 85;
xlSurfaceTopViewWireframe = 86;
xlBubble = 15;
xlBubble3DEffect = 87;
xlStockHLC = 88;
xlStockOHLC = 89;
xlStockVHLC = 90;
xlStockVOHLC = 91;
xlCylinderColClustered = 92;
xlCylinderColStacked = 93;
xlCylinderColStacked100 = 94;
xlCylinderBarClustered = 95;
xlCylinderBarStacked = 96;
xlCylinderBarStacked100 = 97;
xlCylinderCol = 98;
xlConeColClustered = 99;
xlConeColStacked = 100;
xlConeColStacked100 = 101;
xlConeBarClustered = 102;
xlConeBarStacked = 103;
xlConeBarStacked100 = 104;
xlConeCol = 105;
xlPyramidColClustered = 106;
xlPyramidColStacked = 107;
xlPyramidColStacked100 = 108;
xlPyramidBarClustered = 109;
xlPyramidBarStacked = 110;
xlPyramidBarStacked100 = 111;
xlPyramidCol = 112;
xl3DColumn = -4100;
xlLine = 4;
xl3DLine = -4101;
xl3DPie = -4102;
xlPie = 5;
xlXYScatter = -4169;
xl3DArea = -4098;
xlArea = 1;
xlDoughnut = -4120;
xlRadar = -4151;
{XlBarShape}
xlBox = 0;
xlPyramidToPoint = 1;
xlPyramidToMax = 2;
xlCylinder = 3;
xlConeToPoint = 4;
xlConeToMax = 5;
{XlSheetType}
xlChart = -4109;
xlDialogSheet = -4116;
xlExcel4IntlMacroSheet = 4;
xlExcel4MacroSheet = 3;
xlWorksheet = -4167;