|
本帖最后由 Kelidai 于 2014-6-4 15:26 编辑
- Private Sub CommandButton4_Click()
- Application.ScreenUpdating = False
- Application.Calculation = xlCalculationManual
- Dim i ,j As Integer
- Sheet1.Hyperlinks.Delete
- Sheet1.Columns("B:B").HorizontalAlignment = xlCenter
- Dim MyName, dic, Did, t, F, TT, MyFileName, objShell, objFolder, lj, Ke, sz, Sh, rng As Range, cell As Range, Myr&, arr, d, k
- Dim objOL As Object
- Dim RS1, RS2, db1
- Dim itmNewMail As Object
- lj = "D:\works\order\NORMAL"
- 'lj = "C:\Documents and Settings\franklin.dai\My Documents\我的扫描"
- Set dic = CreateObject("Scripting.Dictionary") '创建一个字典对象
- Set Did = CreateObject("Scripting.Dictionary")
- dic.Add (lj), ""
- i = 0
- Do While i < dic.Count
- Ke = dic.keys '开始遍历字典
- MyName = Dir(Ke(i), vbDirectory) '查找目录
- Do While MyName <> ""
- If MyName <> "." And MyName <> ".." Then
- If (GetAttr(Ke(i) & MyName) And vbDirectory) = vbDirectory Then '如果是次级目录
- dic.Add (Ke(i) & MyName & ""), "" '就往字典中添加这个次级目录名作为一个条目
- End If
- End If
- MyName = Dir '继续遍历寻找
- Loop
- i = i + 1
- Loop
- Did.Add ("文件清单"), ""
- For Each Ke In dic.keys
- MyFileName = Dir(Ke & "*.*")
- Do While MyFileName <> ""
- Did.Add (Ke & MyFileName), ""
- MyFileName = Dir
- Loop
- Next
- Sh = Did.keys
- Set d = CreateObject("Scripting.Dictionary")
- Myr = Sheet1.[A65536].End(xlUp).Row
- arr = Sheet1.Range("B1:D" & Myr)
- For i = 3 To UBound(arr)
- d(arr(i, 1) & "-" & arr(i, 3)) = arr(i, 2)
- Next
- k = d.keys
- t = d.items
- For i = 0 To d.Count - 1
- Set db1 = OpenDatabase(stpath, False, False, ";pwd=2345")
- Set RS2 = db1.OpenRecordset(Name:="供应商资料", Type:=dbOpenDynaset)
- RS2.FindFirst "Vendor_code ='" & t(i) & "'"
- For j = 0 To Did.Count - 1
- If Sh(j) Like "*" & k(i) & "*.*" Then
- Set objOL = CreateObject("Outlook.Application")
- Set itmNewMail = objOL.CreateItem(olMailItem)
- With itmNewMail
- .Subject = "订单" & "-" & k(i)
- .body = Left(RS2.Fields("Contact").Value, 1) & "经理" & ":" & Chr(13) & "请尽快安排附件的订单,记得及时回传确认,并每周四提供一次交期确认" & Chr(13) & Chr(13) & "ABC (ABC)" & Chr(13) & "采购经理" & Chr(13) & "深圳ABC数字通信有限公司" & Chr(13) & "Tel: 0755-888XXXXX-8888" & Chr(13) & "Fax: 0755-888XXXXX"
- .To = RS2.Fields("E-Mail").Value
- .Attachments.Add Sh(j)
- .Display
- DoEvents
- SendKeys "%s", Wait:=True
- SetTimer 0, 1000, 0, AddressOf WinProcA
- End With
- Set objOL = Nothing
- Set itmNewMail = Nothing
- Exit For
- End If
- Next j
- Next i
- Application.ScreenUpdating = True
- Application.Calculation = xlCalculationAutomatic
- End Sub
- 主要功能:查找指定文件下的文件。
- 根据供应商资料查找邮件地址
- 将符合要求的文件作为附件发送。
复制代码 |
|