今天把公司的電腦升級成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
Sub 文件()Set file = CreateObject("scripting.filesystemobject")For Each fils In file.getfolder("c:\").FilesFilename = Filename & fils.Name & Chr(13)NextMsgBox FilenameEnd Sub