標題:
[發問]
求救~無限迴圈~
[打印本頁]
作者:
av8d
時間:
2013-3-14 14:01
標題:
求救~無限迴圈~
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.DisplayAlerts = False
If Target.Address(0, 0) = "A1" Then
Dim Bo As Workbook, Save_Name As String, E As Object
With ActiveWorkbook
Save_Name = "D:\" & [A1] & ".xls"
.Sheets("工作表1").Copy
End With
With ActiveWorkbook
For Each E In .VBProject.VBComponent
E.CodeModule.DeleteLines 1, E.CodeModule.CountOfLines
Next
.SaveCopyAs Save_Name
.Close False
End With
[A1].Select
End If
Application.DisplayAlerts = True
End Sub
複製代碼
我在 [A1].Select 下方新增一行 Selection.ClearContents
結果變成無限迴圈~不知道為什麼會這樣~懇求大大們幫忙~謝謝!
作者:
GBKEE
時間:
2013-3-14 14:22
回復
1#
av8d
這問題很常見,試試看
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Bo As Workbook, Save_Name As String, E As Object
Application.EnableEvents = False '停止物件的觸發事件
Application.DisplayAlerts = False
If Target.Address(0, 0) = "A1" Then
With ActiveWorkbook
Save_Name = "D:\" & [A1] & ".xls"
.Sheets("工作表1").Copy
End With
With ActiveWorkbook
For Each E In .VBProject.VBComponent
E.CodeModule.DeleteLines 1, E.CodeModule.CountOfLines
Next
.SaveCopyAs Save_Name
.Close False
End With
[A1].Select
Selection.ClearContents '這工作表中的儲存格有修改
'** Worksheet_Change (這是工作中的儲存格有修改時->預設的觸發事件程序)
End If
Application.DisplayAlerts = True
Application.EnableEvents = True '恢復物件的觸發事件
End Sub
複製代碼
作者:
av8d
時間:
2013-3-14 15:00
回復
2#
GBKEE
謝謝G大~完成
是否可以再詢問一下
我下了這個判斷[A1].Select
是希望輸入以後~依然維持在A1
但是當我滑鼠點到A2就不會跳到A1了
因為判斷有改變才執行
請問是否可以在滑鼠指到A1以外的儲存格
讓他自動跳到A1呢?不知道有沒有這種判斷?再次感謝!
作者:
GBKEE
時間:
2013-3-14 15:24
回復
3#
av8d
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address(0, 0) <> "A1" Then [A1].Select
End Sub
複製代碼
[attach]14357[/attach]
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)