打开excel根据条件决定是否自动执行宏 求vba宏代码

2024-12-16 20:16:16
推荐回答(3个)
回答1:

Private Sub Workbook_Open()
With Sheets(1)
If WorksheetFunction.CountA(.Range("a:a")) = 0 Then Call macro
ThisWorkbook.Save
If Hour(Time) >= 1 And Hour(Time) <= 15 Then ThisWorkbook.Close
End With
End Sub

回答2:

Private Sub Workbook_Open()
With Sheets(1)
If WorksheetFunction.CountA(.Range("a:a")) > 0 Then Call macro
ThisWorkbook.Save
If Hour(Time) >= 1 And Hour(Time) <= 15 Then ThisWorkbook.Close
End With
End Sub
统计单元格要大于0才对!

回答3:

Private Sub Workbook_Open()
ano = Sheet1.[a65535].End(xlUp).Row
If (ano = 1 And Len(Trim(Sheet1.[a1])) > 0) Or ano > 1 Then
Call 宏
End If

If Time > "01:00:00" And Time <= "15:00:00" Then
ThisWorkbook.Close True
Else
ThisWorkbook.Save
End If
End Sub