[attach]18698[/attach]
Sub test()
Dim mybook As Workbook
Dim mysh As Worksheet, dtsh As Worksheet
Dim cell As Range
Dim num As Long
Dim secAutomation As MsoAutomationSecurity
Set mybook = ThisWorkbook
Set mysh = mybook.ActiveSheet
mypath = mybook.Path & "\"
dtfile = Dir(mypath & "*.xls")
r = 2
Do Until dtfile = ""
If dtfile <> mybook.Name Then
ck = ""
For Each wb In Workbooks
If wb.Name = dtfile Then ck = "Y"
Next wb
If ck = "" Then Workbooks.Open mypath & dtfile
Application.AutomationSecurity = secAutomation '-----------------巨集啟用
Set dtsh = Workbooks(dtfile).ActiveSheet
r = r + 1
End If
If dtfile <> mybook.Name Then
Workbooks(dtfile).Close savechanges:=False
End If
dtfile = Dir
Loop
End Sub作者: yangjie 時間: 2014-7-15 01:00
回復 1#lichang
我是這樣做的 參考參考
dim wb as workbooks
dim wb1 as workbooks
Set wb = ThisWorkbooks
Application.EnableEvents = False '使打開wb1時 巨集失效
Set wb1 = Workbooks.Open(FileName)
With wb1
.Sheets(SHname).Cells.Copy wb.Sheets("Temp").Cells(1, 1)
Application.CutCopyMode = False
.Close False
End With
Set wb1 = Nothing
Application.EnableEvents = True '恢復巨集效力作者: lichang 時間: 2014-7-15 17:34