Board logo

標題: Excel 2003錄製的巨集,在Excel2007該如何修改 [打印本頁]

作者: acdx    時間: 2012-5-17 15:23     標題: Excel 2003錄製的巨集,在Excel2007該如何修改

本帖最後由 acdx 於 2012-5-17 15:25 編輯

Dim mybtm As Integer
        mypath = ActiveWorkbook.Path
  
      Set fs = Application.FileSearch
   With fs
    .LookIn = mypath
    .Filename = "zzz_results.xls"

    If .Execute = 1 Then

        mymsg = "zzz_results.xls exist, Overwrite it ?"
        mytitle = " WARNING"
               
        mybtn = MsgBox(mymsg, vbYesNo + vbExclamation, mytitle)
        
        If mybtn = vbNo Then GoTo 40
        
        Else
         Workbooks.Add
         ActiveWorkbook.SaveAs Filename:=mypath & "\" & "zzz_results.xls"
         
        End If
                     
        Workbooks.Open Filename:=mypath & "\" & "zzz_results.xls"
        Cells.ClearContents
        ActiveWorkbook.Save
  
        End With
作者: Hsieh    時間: 2012-5-17 15:30

回復 1# acdx


    mypath = ThisWorkbook.Path & "\"
fs = Dir(mypath & "zzz_results.xls")
If fs = "" Then
   Workbooks.Add
   ActiveWorkbook.SaveAs Filename:=mypath & "\" & "zzz_results.xls"
Else
       mymsg = "zzz_results.xls exist, Overwrite it ?"
        mytitle = " WARNING"
               
        mybtn = MsgBox(mymsg, vbYesNo + vbExclamation, mytitle)
        
        If mybtn = vbNo Then GoTo 40
End If
作者: acdx    時間: 2012-5-17 17:18

回復 2# Hsieh

Set myFSObj = Application.FileSearch

With myFSObj
  .LookIn = ActiveWorkbook.Path
  .Filename = "*.xls"
  If .Execute(SortBy:=msoSortByFileName, sortorder:=msoSortOrderAscending) > 0 Then
  For i = 1 To .FoundFiles.Count
  wkfile = .FoundFiles(i)
  resultfile = mypath & "\" & "zzz_results.xls"
  If resultfile = .FoundFiles(i) And i = .FoundFiles.Count Then GoTo 20
  If resultfile = .FoundFiles(i) Then GoTo 30
  Workbooks.Open Filename:=wkfile
若是這樣該如何改呢?




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)