[VBA ] Application.FileSearch要怎麼改寫?

看板Visual_Basic作者 (仁甫哥超MAN!!!)時間11年前 (2014/09/30 15:43), 編輯推噓3(3011)
留言14則, 3人參與, 最新討論串1/1
今天把公司的電腦升級成office2010 發現原本的巨集不能使用 偵錯發現是Application.FileSearch在2007以後的版本就不能使用了 原程式碼如下: Sub AutoCopyTableTofile() defaultfile = Application.ActiveDocument.Name With Application.FileSearch .FileName = "獎懲統計表.doc" .LookIn = "c:\獎懲月報" .Execute If .FoundFiles.Count > 0 Then Documents.Open FileName:="c:\獎懲月報\獎懲統計表.doc" Documents(defaultfile).Activate Selection.Tables(1).Range.Copy Documents("獎懲統計表.doc").Activate Selection.Paste Documents(defaultfile).Close Else MsgBox ("未找到===>獎懲統計表.doc<==檔案") Exit Sub End If End With End Sub ---- 請問這段程式碼要怎麼改寫成能在office2007以後版本run的巨集呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.69.153.120 ※ 文章網址: http://www.ptt.cc/bbs/Visual_Basic/M.1412063010.A.BDD.html

09/30 15:57, , 1F
不要存在c碟看看
09/30 15:57, 1F

09/30 16:04, , 2F
跟C槽無關啦 是程式碼本身不相容2007以後的版本
09/30 16:04, 2F

09/30 16:21, , 3F
改用findfiles
09/30 16:21, 3F

09/30 16:26, , 4F
用findfiles不行耶
09/30 16:26, 4F

09/30 16:52, , 5F
Sub 文件()
09/30 16:52, 5F

09/30 16:52, , 6F
Set file = CreateObject("scripting.filesystemobject"
09/30 16:52, 6F

09/30 16:52, , 7F
)
09/30 16:52, 7F

09/30 16:52, , 8F
For Each fils In file.getfolder("c:\").Files
09/30 16:52, 8F

09/30 16:52, , 9F
Filename = Filename & fils.Name & Chr(13)
09/30 16:52, 9F

09/30 16:52, , 10F
Next
09/30 16:52, 10F

09/30 16:52, , 11F
MsgBox Filename
09/30 16:52, 11F

09/30 16:52, , 12F
End Sub
09/30 16:52, 12F

09/30 22:23, , 13F
用DIR()應該就可以混過去了 這個VBA的老函數一直沒刪掉
09/30 22:23, 13F

09/30 22:24, , 14F
DIR function on MSDN: http://goo.gl/UxqfH1
09/30 22:24, 14F
文章代碼(AID): #1KAbyYlT (Visual_Basic)
文章代碼(AID): #1KAbyYlT (Visual_Basic)