If ActiveWindow.Caption <> "BOOK1.xls" Then MsgBox ActiveWindow.Caption
或是
If ActiveWorkbook.Name <> "BOOK1.xls" Then MsgBox ActiveWorkbook.Name
複製代碼
作者: t8899 時間: 2013-11-1 15:03 標題: 請問此巨集錯誤如何修改??
本帖最後由 t8899 於 2013-11-1 15:17 編輯
型態不符合 附檔[attach]16542[/attach]
在開另一檔案後執行會錯誤 ,不開則不會???
Public Runtime
Sub a123()
If Range("i1").Value <> 1 Then
On Error Resume Next
Application.OnTime EarliestTime:=TimeValue(Runtime), _
Procedure:="a123", Schedule:=False
Exit Sub
On Error GoTo 0
End If
Macro1
If Range("k14") = 4 Then mytime = "00:00:15"
Runtime = Now + TimeValue(mytime)
Application.OnTime Runtime, "Sheet1.a123"
End Sub作者: sunnyso 時間: 2013-11-1 15:48
1.15秒自動執行一次,沒問題
但當打開A檔案,視窗停留在A檔案,則所得的數字是不對的???
2.單用Sheets("Sheet1").Select 或 With Sheets("Sheet1")
執行會寫進A檔案的工作表裡???
Sub Macro1()
Dim ah As Workbook
Set ah = ActiveWorkbook
' Sheets("Sheet1").Select
' With Sheets("Sheet1")
Workbooks("book2.xls").Sheets("Sheet1").Range("a1").Value = Now
t = [TEXT(A1,"hh:mm")+LOOKUP(--TEXT(A1,"s"),{0,15,30,45})/86400]
Workbooks("book2.xls").Sheets("Sheet1").Range("a65536").End(xlUp).Offset(1).Value = Format(t, "hh:mm:ss")
' End With
ah.Activate
End Sub
[attach]16547[/attach]作者: GBKEE 時間: 2013-11-1 21:41
t = [TEXT(NOW(),"hh:mm")+LOOKUP(--TEXT(NOW(),"s"),{0,15,30,45})/86400]
複製代碼
作者: t8899 時間: 2013-11-2 08:29
回復 10#GBKEE
謝謝
昨晚想了另一個方法如下:
儲存格B1=TEXT(FLOOR(A1,"0:00:15"),"hh:mm:SS")
Sub Macro1()
Dim ah As Workbook
Set ah = ActiveWorkbook
Workbooks("book2.xls").Sheets("Sheet1").Range("a1").Value = Now
Workbooks("book2.xls").Sheets("Sheet1").Range("a65536").End(xlUp).Offset(1).Value =Workbooks("book2.xls").Sheets("Sheet1").Range("B1").Value
ah.Activate
END SUB作者: GBKEE 時間: 2013-11-2 09:25