vb和excel的问题

来源:百度知道 编辑:UC知道 时间:2024/06/16 13:01:10
我要比对两个excel中的数据 如果相同,加颜色,或则替换
Dim ExcelApp As Excel.Application
Dim ExcelBook1 As Excel.Workbook
Dim ExcelBook2 As Excel.Workbook
Dim ExcelSheet1 As Excel.Worksheet
Dim ExcelSheet2 As Excel.Worksheet

Private Sub Command1_Click()
Dim a As String
Dim b As String

Dim n As Long
Dim m As Long
Dim ra As String
Dim rb As String
Dim rangecella As String
Dim rangecellb As String

a = Text1.Text
b = Text2.Text

Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook1 = ExcelApp.Workbooks.Open(App.Path & "\" & a & ".xls") '打开测试文件
Set ExcelBook2 = ExcelApp.Workbooks.Open(App.Path & "\" & b & ".xls")

ExcelApp.Visible = False '设置EXCEL对象不可见
Set ExcelSheet1 = Excel.Worksheets("Sheet1")
Set ExcelSheet2 = Excel.Worksheets("Sheet1")
n = 1
Do
rangec

Option Explicit

Dim ExcelApp As Excel.Application
Dim ExcelBook1 As Excel.Workbook
Dim ExcelBook2 As Excel.Workbook
Dim ExcelSheet1 As Excel.Worksheet
Dim ExcelSheet2 As Excel.Worksheet

Private Sub Command1_Click()
Dim a As String
Dim b As String

Dim n As Long
Dim m As Long
Dim ra As String
Dim rb As String
Dim rangecella As String
Dim rangecellb As String

a = Text1.Text
b = Text2.Text

If Trim(a) = "" Or Trim(b) = "" Then
Exit Sub
End If

Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook1 = ExcelApp.Workbooks.Open(App.Path & "\" & a & ".xls") '打开测试文件
Set ExcelBook2 = ExcelApp.Workbooks.Open(App.Path & "\" & b & ".xls")

ExcelApp.Vis