|
- Sub Macro1()
- Dim FirstRow, LastRow, arr, i&, f$, p1$, p$, lr&
- Dim cnn As Object, SQL$, t
- p1 = ThisWorkbook.Path & ""
- f = p1 & "原文件.xls"
- lr = Range("a65536").End(xlUp).Row - 1
- Do
- FirstRow = InputBox(Prompt:="请输入开始序号:>=1且<=" & lr, Title:="输入开始序号", Default:=1)
- If StrPtr(FirstRow) = 0 Then Exit Sub
- Loop Until Val(FirstRow) > 0 And Val(FirstRow) <= lr
- Do
- LastRow = InputBox(Prompt:="请输入结束序号:>=" & FirstRow & "且<=" & lr, Title:="输入结束序号", Default:=lr)
- If StrPtr(LastRow) = 0 Then Exit Sub
- Loop Until Val(LastRow) >= FirstRow And Val(LastRow) <= lr
- arr = Range("a" & FirstRow + 1).Resize(lr - FirstRow + 1, 2)
- For i = 1 To UBound(arr)
- If Len(arr(i, 2)) Then
- p = p1 & "明细" & arr(i, 2) & ".xls"
- If Dir(p) <> "" Then Kill p
- FileCopy f, p
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider = Microsoft.Jet.Oledb.4.0;Extended Properties ='Excel 8.0;hdr=no';Data Source =" & p
- If IsNumeric(arr(i, 2)) Then
- t = arr(i, 2)
- Else
- t = "'" & arr(i, 2) & "'"
- End If
- SQL = "update [BOM$a3:a3] set f1 =" & t
- cnn.Execute SQL
- End If
- Next
- cnn.Close
- Set cnn = Nothing
- MsgBox "ok"
- End Sub
- 请测试:
复制代码 |
评分
-
1
查看全部评分
-
|