Consulting

Results 1 to 6 of 6

Thread: Stoping a workbook from opening when macros are disabled?

  1. #1
    VBAX Regular kane's Avatar
    Joined
    Mar 2005
    Location
    Huntsville, AL
    Posts
    35
    Location

    Exclamation Stoping a workbook from opening when macros are disabled?

    Can you stop a workbook from opening when macros are disabled and give a messagebox to the user saying, "To enter the workbook please enable your macros."

    And can you name a workbook after the contents of cell "A1"?

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi Kane, welcome to VBAX!

    Addressing your questions seperately as 1 and 2 ...


    Question 1:
    You can't really. Not with code. What you can do is do some (of what I call) 'backwards programming'. Examples can be found ..

    http://j-walk.com/ss/excel/tips/tip100.htm

    http://www.mrexcel.com/board2/viewtopic.php?t=121978

    http://www.mrexcel.com/board2/viewtopic.php?t=101300

    Question 2:
    You can use something like this ..

    Sub RenameWorkbookAfter_A1()
        Dim fPath As String
        fPath = ThisWorkbook.FullName
        ThisWorkbook.SaveAs ThisWorkbook.Path & "\" & Sheets("Sheet1").Range("A1").Value
        Kill fPath
    End Sub
    Note: If you DON'T want to delete the original copy of the file (prior to saveAs) then delete the Kill .. line (last line of code).


    HTH

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    A simple method to try, but not a high level of security; hide or password protect the sheets with a BeforeClose macro which requires an OnOpen macro to restore the sheets for use. If you need code for this, let us know.

    To name the book, try

    MyDir = "C:\ATest\"
    MyFile = Sheets("Sheet1").Range("A1").Text
    ActiveWorkbook.SaveAs Filename:=MyDir & MyFile

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Which, btw, these methods could fail if the file already exists and you choose to cancel out of the save. You can code around that though, depending on if you want to overwrite or not..

  5. #5
    VBAX Regular kane's Avatar
    Joined
    Mar 2005
    Location
    Huntsville, AL
    Posts
    35
    Location

    Works for me.

    Wow, thanks. Both problems solved. This is a great service. Keep up the good work.

  6. #6
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Great, glad it works for you! I'll go ahead and mark this solved. You can do so on your posts by going to Thread Tools --> Mark Thread Solved --> Perform Action.


    Take care!

Posting Permissions

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