Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Workbook_Open not working?

I'm still a beginner at this, so would appreciate an expert explaining what
is going on here. My Workook_Open macro (follows) was not running at all.
----------------------
Private Sub Workbook_Open()

Sheets("Audit").Select

If Range("E2").Value = "New" Then
Range("A2").Value = Application.UserName
Range("B2").Value = Date
Range("C2").Value = Time
Randomize
Range("D2").Value = Rnd()
ActiveSheet.Protect Password:="A" & Int(Rnd() * 10000000000#)
ActiveSheet.Visible = False
End If

Sheets("Profiles").Select

End Sub
----------------------
I added the following lines to the macro to try and see why
----------------------
If Range("E2").Value < "New" Then
Range("A2").Value = Application.UserName
End If
----------------------
and suddenly it did work, even though the code itself should not have
resulted in any difference. Is there some compilation step that I'm
overlooking? This macro is going to get recycled into several different
spreadsheets and I need to document how to make it work for future
maintainers.

Many thanks,
Geoff.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Workbook_Open not working?

Hi Geoff,

Looks like Range("E2").Value < "New", so your original code won't pass the
'If' test, unlike your added code.

Regards,
Peter T

"Geoff C" wrote in message
...
I'm still a beginner at this, so would appreciate an expert explaining

what
is going on here. My Workook_Open macro (follows) was not running at all.
----------------------
Private Sub Workbook_Open()

Sheets("Audit").Select

If Range("E2").Value = "New" Then
Range("A2").Value = Application.UserName
Range("B2").Value = Date
Range("C2").Value = Time
Randomize
Range("D2").Value = Rnd()
ActiveSheet.Protect Password:="A" & Int(Rnd() * 10000000000#)
ActiveSheet.Visible = False
End If

Sheets("Profiles").Select

End Sub
----------------------
I added the following lines to the macro to try and see why
----------------------
If Range("E2").Value < "New" Then
Range("A2").Value = Application.UserName
End If
----------------------
and suddenly it did work, even though the code itself should not have
resulted in any difference. Is there some compilation step that I'm
overlooking? This macro is going to get recycled into several different
spreadsheets and I need to document how to make it work for future
maintainers.

Many thanks,
Geoff.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Workbook_Open not working?

Hi Peter, the additional bit was deliberately reduced. It was the original If
block that ran (as it should have done from the start), hence my bafflement.
Geoff.

"Peter T" wrote:

Hi Geoff,

Looks like Range("E2").Value < "New", so your original code won't pass the
'If' test, unlike your added code.

Regards,
Peter T

"Geoff C" wrote in message
...
I'm still a beginner at this, so would appreciate an expert explaining

what
is going on here. My Workook_Open macro (follows) was not running at all.
----------------------
Private Sub Workbook_Open()

Sheets("Audit").Select

If Range("E2").Value = "New" Then
Range("A2").Value = Application.UserName
Range("B2").Value = Date
Range("C2").Value = Time
Randomize
Range("D2").Value = Rnd()
ActiveSheet.Protect Password:="A" & Int(Rnd() * 10000000000#)
ActiveSheet.Visible = False
End If

Sheets("Profiles").Select

End Sub
----------------------
I added the following lines to the macro to try and see why
----------------------
If Range("E2").Value < "New" Then
Range("A2").Value = Application.UserName
End If
----------------------
and suddenly it did work, even though the code itself should not have
resulted in any difference. Is there some compilation step that I'm
overlooking? This macro is going to get recycled into several different
spreadsheets and I need to document how to make it work for future
maintainers.

Many thanks,
Geoff.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Workbook_Open not working?

This doesn't work - right

If Range("E2").Value = "New" Then
' original code

But this does work
If Range("E2").Value < "New" Then

From where I'm looking E2 < "New". So, and quite correctly, your original
code between If...End If does not appear to work.

Why are you baffled !

Regards,
Peter T

"Geoff C" wrote in message
...
Hi Peter, the additional bit was deliberately reduced. It was the original

If
block that ran (as it should have done from the start), hence my

bafflement.
Geoff.

"Peter T" wrote:

Hi Geoff,

Looks like Range("E2").Value < "New", so your original code won't pass

the
'If' test, unlike your added code.

Regards,
Peter T

"Geoff C" wrote in message
...
I'm still a beginner at this, so would appreciate an expert explaining

what
is going on here. My Workook_Open macro (follows) was not running at

all.
----------------------
Private Sub Workbook_Open()

Sheets("Audit").Select

If Range("E2").Value = "New" Then
Range("A2").Value = Application.UserName
Range("B2").Value = Date
Range("C2").Value = Time
Randomize
Range("D2").Value = Rnd()
ActiveSheet.Protect Password:="A" & Int(Rnd() * 10000000000#)
ActiveSheet.Visible = False
End If

Sheets("Profiles").Select

End Sub
----------------------
I added the following lines to the macro to try and see why
----------------------
If Range("E2").Value < "New" Then
Range("A2").Value = Application.UserName
End If
----------------------
and suddenly it did work, even though the code itself should not have
resulted in any difference. Is there some compilation step that I'm
overlooking? This macro is going to get recycled into several

different
spreadsheets and I need to document how to make it work for future
maintainers.

Many thanks,
Geoff.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Workbook_Open not working?

VBA comparisons are case sensitive. Maybe something like:

If lcase(Range("E2").Value) = lcase("New") Then

would help.

Geoff C wrote:

I'm still a beginner at this, so would appreciate an expert explaining what
is going on here. My Workook_Open macro (follows) was not running at all.
----------------------
Private Sub Workbook_Open()

Sheets("Audit").Select

If Range("E2").Value = "New" Then
Range("A2").Value = Application.UserName
Range("B2").Value = Date
Range("C2").Value = Time
Randomize
Range("D2").Value = Rnd()
ActiveSheet.Protect Password:="A" & Int(Rnd() * 10000000000#)
ActiveSheet.Visible = False
End If

Sheets("Profiles").Select

End Sub
----------------------
I added the following lines to the macro to try and see why
----------------------
If Range("E2").Value < "New" Then
Range("A2").Value = Application.UserName
End If
----------------------
and suddenly it did work, even though the code itself should not have
resulted in any difference. Is there some compilation step that I'm
overlooking? This macro is going to get recycled into several different
spreadsheets and I need to document how to make it work for future
maintainers.

Many thanks,
Geoff.


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Workbook_Open() Not working Dave Excel Programming 4 September 7th 06 02:41 AM
Workbook_Open - Multiple Events not all working Punsterr Excel Programming 2 October 6th 05 07:44 AM
Workbook_Open not working Sheena N via OfficeKB.com Excel Discussion (Misc queries) 4 May 6th 05 01:31 AM
Workbook_Open and Workbook_BeforeClose not working Don[_19_] Excel Programming 0 August 10th 04 06:58 PM
Workbook_Open event not working jason Excel Programming 2 September 7th 03 04:02 PM


All times are GMT +1. The time now is 04:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"