この人頭いいなと思ったエピソード

Zフォルダ内(下に複数のフォルダがある)pdf fileが入っており、エクセルのA列(A2~Axx)に入っている名前のものをXフォルダにCOPYする方法を教えて頂けませんか?※Zフォルダの中のどのフォルダに入っているかはpdfファイルによりバラバラです。よろしくお願いします。

A 回答 (2件)

こんばんは。



If f.Attributes < 1024 Then '特別なフォルダは除外
これだけで済むかは不明

'//
Option Explicit

Private myRange As Range
Private FSO As Object
Private Const DST As String = "C:\X\" '末尾には¥を入れる
Sub FindAndCopy1()
 Const mPath = "C:\Z\"  '末尾には¥を入れる
 Set myRange = Range("A2", Cells(Rows.Count, 1).End(xlUp)) 'A列
 Set FSO = CreateObject("Scripting.FileSystemObject")
 FileSearchN mPath
 Set FSO = Nothing
End Sub

Sub FileSearchN(Path As String)
  Dim buf As Variant
  Dim f As Object
  Dim ret As Variant
  buf = Dir(Path & "\*.pdf")  '拡張子
  Do While buf <> ""
    ret = Application.Match(buf, myRange, 0)
    If IsNumeric(ret) Then
     If Not FSO.FileExists(DST & buf) Then
      FSO.CopyFile Path & "\" & buf, DST
     End If
    End If
    buf = Dir()
    DoEvents
  Loop
  With FSO
    For Each f In .GetFolder(Path).SubFolders
      If f.Attributes < 1024 Then '特別なフォルダは除外
       Call FileSearchN(f.Path)
      End If
      DoEvents
    Next f
  End With
End Sub
    • good
    • 0

以下が参考になると思います



ファイル検索の処理速度をUPさせるには?
http://www.moug.net/faq/viewtopic.php?t=70650

moug は6ヶ月でQAは消えるみたいなので・・・


※ 前回のご質問

VBAを使用した保存方法
http://oshiete.goo.ne.jp/qa/8961276.html

急いでいた?
問題が解決できたのか、わかりませんが
回答した側にとっては、役に立ったのかくらいは知りたいものです。
    • good
    • 2

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!