B
Boiler-Todd
If I run a macro for a workbook with "Sub Workbook_Open()", will the macro
run first before the functions like "Now()" in the workbook updates. I am
triggering my macro off the date function of Now().
For example, I did work today Now(10/5/09). When I open the workbook
tomorrow, I want the macro to run with the date (10/5/09) first then have the
function update to Now(10/6/09).
Here is my code. It works but I haven't tried it over a long period.
ub Workbook_Open()
Dim cell As Range, intSheet As Integer
Dim wS1 As Worksheet
Dim wSA As Worksheet
Dim wS2 As Worksheet
Dim wSB As Worksheet
Dim wS3 As Worksheet
Dim wSC As Worksheet
Dim Date1 As Date
Dim Date2 As Date
Dim Date3 As Date
Set wS1 = ThisWorkbook.Sheets(1)
Set wSA = ThisWorkbook.Sheets("History 1")
Set wS2 = ThisWorkbook.Sheets(2)
Set wSB = ThisWorkbook.Sheets("History 2")
Set wS3 = ThisWorkbook.Sheets(3)
Set wSC = ThisWorkbook.Sheets("History 3")
' For intSheet = 1 To 3
If Sheets(3).Range("H1").Value < Date Then
wS1.Range("A12:K16").Copy wSA.Range("A12:K16")
wS2.Range("A12:K16").Copy wSB.Range("A12:K16")
wS3.Range("A12:K16").Copy wSC.Range("A12:K16")
Date1 = wS1.Range("H1")
Date2 = wS2.Range("H1")
Date3 = wS3.Range("H1")
wSA.Range("H1") = Date1
wSB.Range("H1") = Date2
wSC.Range("H1") = Date3
For intSheet = 1 To 3
For Each cell In Sheets(intSheet).Range("A12:K16")
If Not cell.Locked Then cell.ClearContents
Next cell
Next
End If
End Sub
run first before the functions like "Now()" in the workbook updates. I am
triggering my macro off the date function of Now().
For example, I did work today Now(10/5/09). When I open the workbook
tomorrow, I want the macro to run with the date (10/5/09) first then have the
function update to Now(10/6/09).
Here is my code. It works but I haven't tried it over a long period.
ub Workbook_Open()
Dim cell As Range, intSheet As Integer
Dim wS1 As Worksheet
Dim wSA As Worksheet
Dim wS2 As Worksheet
Dim wSB As Worksheet
Dim wS3 As Worksheet
Dim wSC As Worksheet
Dim Date1 As Date
Dim Date2 As Date
Dim Date3 As Date
Set wS1 = ThisWorkbook.Sheets(1)
Set wSA = ThisWorkbook.Sheets("History 1")
Set wS2 = ThisWorkbook.Sheets(2)
Set wSB = ThisWorkbook.Sheets("History 2")
Set wS3 = ThisWorkbook.Sheets(3)
Set wSC = ThisWorkbook.Sheets("History 3")
' For intSheet = 1 To 3
If Sheets(3).Range("H1").Value < Date Then
wS1.Range("A12:K16").Copy wSA.Range("A12:K16")
wS2.Range("A12:K16").Copy wSB.Range("A12:K16")
wS3.Range("A12:K16").Copy wSC.Range("A12:K16")
Date1 = wS1.Range("H1")
Date2 = wS2.Range("H1")
Date3 = wS3.Range("H1")
wSA.Range("H1") = Date1
wSB.Range("H1") = Date2
wSC.Range("H1") = Date3
For intSheet = 1 To 3
For Each cell In Sheets(intSheet).Range("A12:K16")
If Not cell.Locked Then cell.ClearContents
Next cell
Next
End If
End Sub