|
楼主 |
发表于 2014-9-2 09:03
|
显示全部楼层
蓝桥玄霜 发表于 2014-9-2 08:19
建议搜索多工作簿提取数据的帖子。很多的。
老师终于把您盼来了,另一位老师帮我写了这段从外部文件导入单词的代码:
Sub Macro1()
On Error GoTo line1
Dim wb As Workbook, d, i%, j&, k%, s&, Myr&
Dim arr, brr(1 To 60000, 1 To 3)
Application.ScreenUpdating = False
Myr = IIf([a1] = "", 1, Sheet1.[a1].End(xlDown).Row)
Set d = CreateObject("scripting.dictionary")
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Show
If .SelectedItems.Count = 0 Then Exit Sub
For i = 1 To .SelectedItems.Count
Set wb = GetObject(.SelectedItems(i))
arr = wb.Sheets(1).UsedRange
wb.Close 0
For j = 2 To UBound(arr) Step 2
For k = 1 To UBound(arr, 2)
If arr(j, k) <> "" And Not d.exists(arr(j, k)) Then
d(arr(j, k)) = arr(j + 1, k): s = s + 1: brr(s, 1) = arr(j, k): brr(s, 2) = arr(j + 1, k)
End If
If j = 2 And k = 1 Then brr(s, 3) = arr(1, 1)
Next
Next
Next
End With
Range("a" & Myr).Resize(s, 3) = brr
Application.ScreenUpdating = True
line1:
End Sub
但是有个问题:
如果导入的表是重名(以表中的标题栏为准)的,如何实现只是对已导入的单词库中同名(即第三列相同)的部分进行更新,当然可能导入的同名表中的单词数量可能增加或减少,这怎么更新呢?
|
|