vb程序中有一段代码是调用Excel的。可是在执行set xlApp = new Excel.Application时候报
"加载dll出错",错误号48。该机器上的Excel是能够使用的搜索了一下以前的帖子,发现也有一些人遇到同样问题。但都没有得到解答。各位高手请出手。相关帖子
http://search.csdn.net/Expert/topic/2133/2133966.xml?temp=.8040583
http://search.csdn.net/Expert/topic/2315/2315108.xml?temp=.3693354
http://search.csdn.net/Expert/topic/380/380694.xml?temp=.9973261
"加载dll出错",错误号48。该机器上的Excel是能够使用的搜索了一下以前的帖子,发现也有一些人遇到同样问题。但都没有得到解答。各位高手请出手。相关帖子
http://search.csdn.net/Expert/topic/2133/2133966.xml?temp=.8040583
http://search.csdn.net/Expert/topic/2315/2315108.xml?temp=.3693354
http://search.csdn.net/Expert/topic/380/380694.xml?temp=.9973261
'Private xlBook As Excel.Workbook
'Private xlSheet As Excel.Worksheet
Private xlApp As Object
Private xlBook As Object
Private xlSheet As ObjectPrivate cellValue As StringPublic strError As String
Public ExportOK As Boolean
Private Sub Class_Initialize()
ExportOK = False
On Error GoTo errHandle:
Set xlApp = CreateObject("Excel.Applaction")
'Set xlApp = New Excel.Application
xlApp.Visible = False
On Error GoTo errHandle:
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
If Val(xlApp.Application.Version) >= 8 Then
Set xlSheet = xlApp.ActiveSheet
Else
Set xlSheet = xlApp
End If
Exit Sub
errHandle:
Err.Raise 100001, , "建立Excel对象时发生错误:" & Err.Description & vbCr & _
"请确保您正确了安装了Excel软件!"
End SubPublic Property Get TextMatrix(Row As Integer, Col As Integer) As Variant
TextMatrix = xlSheet.Cells(Row, Col)
End Property
Public Property Let TextMatrix(Row As Integer, Col As Integer, Value As Variant)
xlSheet.Cells(Row, Col) = Value
End Property'合并单元格
Public Sub MergeCell(bRow As Integer, bCol As Integer, eRow As Integer, eCol As Integer)
xlSheet.Range(GetExcelCell(bRow, bCol) & ":" & GetExcelCell(eRow, eCol)).Select
With xlApp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
End Sub
'打印预览
Public Function PrintPreview() As Boolean
On Error GoTo errHandle:
xlApp.Visible = True
xlBook.PrintPreview True
Exit Function
errHandle:
If Err.Number = 1004 Then
MsgBox "尚未安装打印机,不能预览!", vbOKOnly + vbCritical, "错误"
End If
End Function
'导出
Public Function ExportExcel() As Boolean
xlApp.Visible = True
End Function
'画线
Public Sub DrawLine(bRow As Integer, bCol As Integer, eRow As Integer, eCol As Integer)
On Error Resume Next
xlSheet.Range(GetExcelCell(bRow, bCol) & ":" & GetExcelCell(eRow, eCol)).Select
xlApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
xlApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With xlApp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
'导出记录集到Excel
Public Sub RstExport(Rst As ADODB.Recordset, bRow As Integer, bCol As Integer, GridHead() As String)
Dim i As Integer, j As Integer
For i = bCol To UBound(GridHead) + bCol
With Me
.TextMatrix(bRow, i) = GridHead(i - bCol)
End With
Next
i = 1 + bRow
Do While Not Rst.EOF
For j = 1 To Rst.Fields.Count
If Rst.Fields(j - 1).Type = adChar Or Rst.Fields(j - 1).Type = adVarChar Then
xlSheet.Range(GetExcelCell(i, j) & ":" & GetExcelCell(i, j)).Select
xlApp.Selection.NumberFormatLocal = "@" '已文本方式格式化
End If
Me.TextMatrix(i, j) = checkNull(Rst.Fields(j - 1).Value)
Next
i = i + 1
Rst.MoveNext
Loop
End Sub'或者指定行,列号的Excel编码
Private Function GetExcelCell(Row As Integer, Col As Integer) As String
Dim nTmp1 As Integer
Dim nTmp2 As Integer
Dim sTmp As String
If Col <= 26 Then
sTmp = Chr(Asc("A") + Col - 1)
Else
nTmp1 = Col \ 26
If nTmp1 > 26 Then
Err.Raise 100000, , "列数过大,发生错误"
Exit Function
Else
sTmp = Chr(Asc("A") + nTmp1 - 1)
nTmp1 = Col Mod 26
sTmp = sTmp & Chr(Asc("A") + nTmp1 - 1)
End If
End If
GetExcelCell = sTmp & Row
End Function
'将Null返回为空串
Private Function checkNull(s As Variant) As String
checkNull = IIf(IsNull(s), "", s)
End FunctionPrivate Sub Class_Terminate()
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
End Sub试一下呢?
不是代码问题,如果用你的代码运行,会在Set xlApp = CreateObject("Excel.Applaction")处报同样的错误。
office 2000 microsoft excel 9.0 object
office XP microsoft excel 10.0 object
office 2003 microsoft excel 11.0 object
没有microsoft excel 9.0 Object library 可引用。工程里引用着microsoft excel 11.0 Object library
其他的机器安装了我程序后,只有其中一台出现这样的问题。
另外出现问题的这台机器原来也可以运行,只不过原来没有安装打印机,会使程序设置打印机 时候报错,我修改了一下,增加了对打印机的判断,把编译好的exe重新覆盖掉原来的exe后出现了这个问题。但是肯定不是程序的问题,因为set xlApp = new Excel.Application这句原来能通过,但现在通不过了
ljhdi()
没有microsoft excel 9.0 Object library 可引用。工程里引用着microsoft excel 11.0 Object library office2003才是11.0吧
我的就是
最好用低版本的
microsoft excel x.0 object library
关键这台机器Excel能用,window系统也没有发现什么问题。头就担心这程序拿出去到客户那里安装后也会出现这个问题,而且现在我还没有找到什么解决办法。
需要引用Microsoft ActiveX Data Objects 2.5 Library
'******************定义新的数据记录指针来处理Excel***************************
Dim XlsConn As New ADODB.Connection
Dim Xlsrs As New ADODB.Recordset
Dim XLSsheet, tmp As String
Dim yesno As Integer
Dim XLSnum As Long
Dim itemX As ListItem
XlsConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source= " & CommonDialog1.FileName & ";Extended Properties='Excel 8.0;HDR=Yes'"
XlsConn.CursorLocation = adUseClient
XlsConn.Open
'****************************************************************************
XLSsheet = InputBox("工作簿名字", "请输入", "Sheet1")
If Len(XLSsheet) = 0 Then
MsgBox "工作簿名字不能为空!", 48
On Error Resume Next
Xlsrs.Close
Set Xlsrs = Nothing
XlsConn.Close
Set XlsConn = Nothing
Exit Sub
End If
Xlsrs.Open "select * from " & "[" & XLSsheet & "$]", XlsConn, adOpenKeyset, adLockOptimistic