一生所爱的说说:为什么用VBA这样编程达不到效果

来源:百度文库 编辑:高考问答 时间:2024/04/29 05:28:58
Private Function GetValue(path, file, sheet, ref)
Dim arg As String
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("A1").Address(, , xlR1C1)
GetValue = ExecuteExcel4Macro(arg)
End Function

Sub ValueScan()

p1 = "d:\"
f1 = "book1.xls"
'这个表是所有人员的名字表
s1 = "Sheet1"

p2 = "d:\"
f2 = "book.xls"
'这个表是刷卡的员工表
s2 = "Sheet1"

Dim valuei(10, 10)
Dim valueii(10, 10)
Application.ScreenUpdating = False
For r = 1 To 10
a1 = Cells(r, 1).Address
valuei(r, 1) = GetValue(p1, f1, s1, a1)

'如果在刷卡的员工表中能找到这个员工,那么就退出,继续查找下一个人。
For c = 1 To 10
a2 = Cells(c, 1).Address
valueii(c, 1) = GetValue(p2, f2, s2, a2)
If valuei(r, 1) = valueii(c, 1) Then
Exit For
'在刷卡员工表中找了一轮,没有,就输出这个人的名字,说明他没有刷卡。
Else
Cells(r, 2) = valuei(r, 1)
End If
Next c
Next r
Application.ScreenUpdating = True
End Sub

进入程序以后,在文件菜单里选打开,在选择你要加载的ROM就行了,很简单的