ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Autorun macros on opening (https://www.excelbanter.com/excel-programming/369682-autorun-macros-opening.html)

[email protected]

Autorun macros on opening
 
HI guys,

I am trying to setup a autorun macro on a workbook I have. I am trying
to stop the rest of the office changing the name of this file, as it
wil l have a knock on effect to other report!


How do I set this up, I have tried numerous examples on this site, but
just can't get them working... I was looking also for the code that
will stop users using the SaveAs function on the master template I am
creating..


Your help is greatly appreciated.


Craigy


Simon Lloyd[_849_]

Autorun macros on opening
 

Hi, paste this in to the "This Workbook" module

Private Sub Workbook_BeforeSave _
(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = True Then Cancel = True
End Sub

paste this in to an ordinary module:

Sub Auto_open()
On Error Resume Next
If ThisWorkbook.Name < "Test" Then
Application.Quit
End If
End Sub

If the workbook name is not EXACTLY like the wording "Test" then you
will not be able to open the workbook again, if you had the workbook
named "test" you still would not be able to open it, it MUST be exact!

Regards,
Simon


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=569278


[email protected]

Autorun macros on opening
 
Hi Simon,

Thanks for this.

I don't quite understand the workings behind these, I am sorry, I am
only very new to this. Once I have a grasp of how these work, I can
getting them into my template.

What is "This Workbook" and "Ordinary Module"??

Thanks in advance

Thanks

C


Simon Lloyd wrote:
Hi, paste this in to the "This Workbook" module

Private Sub Workbook_BeforeSave _
(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = True Then Cancel = True
End Sub

paste this in to an ordinary module:

Sub Auto_open()
On Error Resume Next
If ThisWorkbook.Name < "Test" Then
Application.Quit
End If
End Sub

If the workbook name is not EXACTLY like the wording "Test" then you
will not be able to open the workbook again, if you had the workbook
named "test" you still would not be able to open it, it MUST be exact!

Regards,
Simon


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=569278



Simon Lloyd[_851_]

Autorun macros on opening
 

In Excel click on tools, macros, Visual Basic Editor, when it opens yo
will see the worksheet modules and the This Workbook module doulbl
click it to open it!, for an ordinary module right click on Thi
Workbook module choose Insert then choose Module.

Regards,
Simo

--
Simon Lloy
-----------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...nfo&userid=670
View this thread: http://www.excelforum.com/showthread.php?threadid=56927



All times are GMT +1. The time now is 05:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com