|
-
Apr 5th, 2006, 04:56 AM
#1
Thread Starter
Member
[RESOLVED] BeforeClose
I have the following routines inThisWorkbook but althougg I can get the auto_open to work I can't get the BeforeClose to work.
Anyone have any ideas?
VB Code:
Option Explicit
Private Sub auto_open()
For Each ws In ThisWorkbook.Worksheets
If Not ws.Name = "Error" Then
ws.Visible = xlSheetVisible
Else
End If
Next ws
Worksheets("Error").Visible = xlSheetVeryHidden
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.EnableEvents = False
MsgBox ("Closing")
If Not ThisWorkbook.Saved Then
Else
Worksheets("Error").Visible = xlSheetVisible
For Each ws In ThisWorkbook.Worksheets
If Not ws.Name = "Error" Then
ws.Visible = xlSheetVeryHidden
Else
ws.Visible = xlSheetVisible
End If
Next ws
ThisWorkbook.Save
End If
End Sub
Thanks
Last edited by si_the_geek; Apr 5th, 2006 at 05:42 AM.
Reason: corrected VBCode tags
-
Apr 5th, 2006, 05:42 AM
#2
Re: BeforeClose
Moved to Office Development forum.
-
Apr 5th, 2006, 06:15 AM
#3
Re: BeforeClose
Shall I go through your code and first decipher what it supposed to do before trying to figure out how it isn't working? Or can you answer those questions and make it a lot easier?
zaza
-
Apr 5th, 2006, 06:21 AM
#4
Thread Starter
Member
Re: BeforeClose
Actually I think I have just cracked it.
Need to restart Excel when after the code has been dropped in. Not sure why, but it seems to work.
-
Apr 5th, 2006, 07:19 AM
#5
Re: BeforeClose
Why would you need to restart Excel to make this work?
What version of Excel are you running? You shouldnt use the Auto_Open event as its old and only for backwards compatibility.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2006, 07:54 AM
#6
Thread Starter
Member
Re: BeforeClose
Don't know.
Just seemed to work......
What should I use instead of auto_open?
-
Apr 5th, 2006, 07:55 AM
#7
Re: BeforeClose
VB Code:
Private Sub Workbook_Open()
MsgBox "Open"
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2006, 08:02 AM
#8
Thread Starter
Member
Re: BeforeClose
In the Auto_Open (nowWorksheet_Open) I want to place a call to another routine that is in a module.
It doesn't seem to recognise the sub name. How do I call another routine when script is behind ThisWorkbook?
Thanks
-
Apr 5th, 2006, 08:10 AM
#9
Re: BeforeClose
The sub in the module should be declared as Friend or Public.
VB Code:
Public Sub SomeSubOfMine()
MsgBox "Meow!"
End Sub
Then call as usual from ThisWorkbook.
VB Code:
Private Sub WorkBook_Open()
SomeSubOfMine
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2006, 08:16 AM
#10
Thread Starter
Member
Re: BeforeClose
Right, I think I have it tied down now. Thanks all for the help.
-
Apr 5th, 2006, 08:19 AM
#11
Re: BeforeClose
Np, dont forget to Resolve the thread then.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|