Workbooks.Open
"测试.xls"
'读取或写入数据的代码
Workbooks("测试.xls").Close
SaveChanges:=True
Application.ScreenUpdating=True
Private Sub Worksheet_Change(ByVal Target As Range)Dim wb As Workbook, sh, a, m, r
If Target.Column = 7 Then
Set wb = GetObject(ThisWorkbook.Path & "\B.xlsx")
Set sh = wb.Worksheets(1)
a = Target.Value
Set m = sh.Range("D:D").Find(What:=a, LookAt:=xlWhole)
If m Is Nothing Then
Target.Font.ColorIndex = 3
Else
Target.Font.ColorIndex = xlAutomatic
wb.Close
End If
End If
End Sub
数据库对象没添加引用 VBE 界面 工具---引用'引用法
'工具--引用---Microsoft Activex..D...O"
'引用后再声明: Dim conn As New Connection 声明链接对象
' Dim rst As New Recordset声明记录集对象
'创建法
'使用CreateObject函数创建
'Set conn = CreateObject("adodb.connection") '创建ado对象
'Set rst = CreateObject("ADODB.recordset") '创建记录集
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)