看板 Visual_Basic 關於我們 聯絡資訊
今天把公司的電腦升級成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
johnpage: 不要存在c碟看看 09/30 15:57
dudu5566: 跟C槽無關啦 是程式碼本身不相容2007以後的版本 09/30 16:04
johnpage: 改用findfiles 09/30 16:21
dudu5566: 用findfiles不行耶 09/30 16:26
johnpage: Sub 文件() 09/30 16:52
johnpage: Set file = CreateObject("scripting.filesystemobject" 09/30 16:52
johnpage: ) 09/30 16:52
johnpage: For Each fils In file.getfolder("c:\").Files 09/30 16:52
johnpage: Filename = Filename & fils.Name & Chr(13) 09/30 16:52
johnpage: Next 09/30 16:52
johnpage: MsgBox Filename 09/30 16:52
johnpage: End Sub 09/30 16:52
MOONRAKER: 用DIR()應該就可以混過去了 這個VBA的老函數一直沒刪掉 09/30 22:23
MOONRAKER: DIR function on MSDN: http://goo.gl/UxqfH1 09/30 22:24