+ Reply to Thread
Results 1 to 4 of 4

Autorun macros on opening

  1. #1

    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


  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    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

  3. #3

    Re: 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



  4. #4
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    In Excel click on tools, macros, Visual Basic Editor, when it opens you will see the worksheet modules and the This Workbook module doulble click it to open it!, for an ordinary module right click on This Workbook module choose Insert then choose Module.

    Regards,
    Simon

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1