Dim xlApp As Object
Dim xlbook As Object
Dim xlsheet As Object
Private Sub Command1_Click()
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True
Timer1.Enabled = True
End Sub
Private Sub Command2_Click() '关闭
xlApp.Quit
Set xlApp = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
On Error GoTo er
Set xlbook = xlApp.ActiveWorkbook
Set xlsheet = xlbook.ActiveSheet
Print xlsheet.Name '当前工作表
er:
End Sub
代码是在你没切换的时候就运行了,你切换之后又没运行过。