返回列表 上一主題 發帖

[發問] 搜尋複製問題

本帖最後由 hugh0620 於 2012-3-19 10:36 編輯

回復 3# imzues


    我的寫法跟H大大不太一樣
    是比較屬於浮動的路徑~ 提供給你參考~
  1. Private Sub CommandButton1_Click()
  2. '===== 選擇存的路徑=======
  3. With Application.FileDialog(msoFileDialogFolderPicker)
  4.     If .Show = 0 Then Exit Sub
  5.     patch = .SelectedItems(1)
  6.     Application.DefaultFilePath = patch
  7. End With
  8. '=====================
  9. '=====檔案要比對的路徑======
  10. With Application.FileDialog(msoFileDialogFolderPicker)
  11.     If .Show = 0 Then Exit Sub
  12.     fd = .SelectedItems(1)
  13.     If .ButtonName = "確定" Then
  14.     fs = Dir(fd & "\*.xls")
  15.         Do Until fs = ""
  16.            sa = Left(fs, 9)
  17.            Set fk = Sheet1.Range("A:A").Find(sa)
  18.            If Not fk Is Nothing Then
  19.             With Workbooks.Open(fs)
  20.             .SaveAs Application.DefaultFilePath & "\" & fs
  21.             .Close
  22.             End With
  23.            End If
  24.            fs = Dir
  25.         Loop
  26.     End If
  27. End With
  28. '=============================
  29. End Sub
複製代碼
學習才能提升自己

TOP

        靜思自在 : 世上有兩件事不能等:一、孝順 二、行善。
返回列表 上一主題