
VB编写的时候出现“ActiveX部件不能创建对象”
代码如下:Dimb2AsExcel.ApplicationDimxlBookAsExcel.WorkbookDimxlSheetAsExcel.WorksheetSetb...
代码如下:
Dim b2 As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set b2 = CreateObject("Excel.Application")‘这句代码会报错“ActiveX部件不能创建对象”
Set xlBook = b2.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
b2.Visible = True
'*****************************************************
xlSheet.Cells(2, 2) = " 设备动作记录表"
If Option1.Value = True Then
xlSheet.Cells(2, 2) = DTPicker1.Value & " 设备动作记录表"
Else
xlSheet.Cells(2, 2) = DTPicker2.Value & Right$(DTPicker4.Value, 9) & "到" & DTPicker3.Value & Right$(DTPicker5.Value, 9) & " 设备动作记录表"
End If
xlSheet.Columns(7).ColumnWidth = 14
xlSheet.Columns(8).ColumnWidth = 14
xlSheet.Columns(9).ColumnWidth = 14
xlSheet.Columns(10).ColumnWidth = 14
'*****************************************************
For i = 3 To MSFGlizhe.Rows + 2
For j = 1 To MSFGlizhe.Cols - 1
xlSheet.Cells(i, j).Value = MSFGlizhe.TextMatrix(i - 3, j)
Next j
Next i
Dim strRange As String
strRange = "A2:" & Chr(63 + j) & "2"
xlSheet.Range(strRange).Select
strRange = "A2:" & Chr(63 + j) & (i - 1)
With b2.Selection
.HorizontalAlignment = xlCenter
.MergeCells = True
End With
Exit Sub
小弟是初学,那位高手帮帮忙! 展开
Dim b2 As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set b2 = CreateObject("Excel.Application")‘这句代码会报错“ActiveX部件不能创建对象”
Set xlBook = b2.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
b2.Visible = True
'*****************************************************
xlSheet.Cells(2, 2) = " 设备动作记录表"
If Option1.Value = True Then
xlSheet.Cells(2, 2) = DTPicker1.Value & " 设备动作记录表"
Else
xlSheet.Cells(2, 2) = DTPicker2.Value & Right$(DTPicker4.Value, 9) & "到" & DTPicker3.Value & Right$(DTPicker5.Value, 9) & " 设备动作记录表"
End If
xlSheet.Columns(7).ColumnWidth = 14
xlSheet.Columns(8).ColumnWidth = 14
xlSheet.Columns(9).ColumnWidth = 14
xlSheet.Columns(10).ColumnWidth = 14
'*****************************************************
For i = 3 To MSFGlizhe.Rows + 2
For j = 1 To MSFGlizhe.Cols - 1
xlSheet.Cells(i, j).Value = MSFGlizhe.TextMatrix(i - 3, j)
Next j
Next i
Dim strRange As String
strRange = "A2:" & Chr(63 + j) & "2"
xlSheet.Range(strRange).Select
strRange = "A2:" & Chr(63 + j) & (i - 1)
With b2.Selection
.HorizontalAlignment = xlCenter
.MergeCells = True
End With
Exit Sub
小弟是初学,那位高手帮帮忙! 展开
若以下回答无法解决问题,邀请你更新回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询