VB 向打开的EXCEL赋值
展开全部
Private Sub Command1_Click()
Dim a As Integer, b As String
Dim c As Integer, d As Integer
Dim i As Integer, j As Integer
Dim ee(5000) As String, ff(2400) As String
If Dir("D:\Lin Yuan\vb6.0\EXCEL SAP\Temp\excel.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("D:\Lin Yuan\vb6.0\EXCEL SAP\Temp\222.xls") '打开EXCEL工作簿
Set xlSheet = xlBook.Worksheets(2) '打开EXCEL工作表
xlSheet.Activate '激活工作表
For i = 1 To 329
a = a + 1
ee(a) = xlSheet.Cells(i, 1)
ff(a) = xlSheet.Cells(i, 2)
Next i
For i = 1 To 329
For j = i + 1 To 329
If ff(i) = ff(j) Then
b = ee(j)
xlSheet.Cells(i, 3) = b
xlSheet.Cells(i, 4) = ff(j)
End If
Next j
Next i
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏
Else
MsgBox ("EXCEL已打开")
End If
If Not xlBook Is Nothing Then End
End Sub
Dim a As Integer, b As String
Dim c As Integer, d As Integer
Dim i As Integer, j As Integer
Dim ee(5000) As String, ff(2400) As String
If Dir("D:\Lin Yuan\vb6.0\EXCEL SAP\Temp\excel.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("D:\Lin Yuan\vb6.0\EXCEL SAP\Temp\222.xls") '打开EXCEL工作簿
Set xlSheet = xlBook.Worksheets(2) '打开EXCEL工作表
xlSheet.Activate '激活工作表
For i = 1 To 329
a = a + 1
ee(a) = xlSheet.Cells(i, 1)
ff(a) = xlSheet.Cells(i, 2)
Next i
For i = 1 To 329
For j = i + 1 To 329
If ff(i) = ff(j) Then
b = ee(j)
xlSheet.Cells(i, 3) = b
xlSheet.Cells(i, 4) = ff(j)
End If
Next j
Next i
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏
Else
MsgBox ("EXCEL已打开")
End If
If Not xlBook Is Nothing Then End
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
下面语句向指定工作表第x行第y列赋值V
假定xlsSheet为VB中打开了的工作表对象
xlsSheet.cells(x,y).value=v
假定xlsSheet为VB中打开了的工作表对象
xlsSheet.cells(x,y).value=v
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Range("A2").Select
ActiveCell.FormulaR1C1 = "1"
ActiveCell.FormulaR1C1 = "1"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询