+ Reply to Thread
Results 1 to 2 of 2

macro code to change file-opening password

  1. #1
    Registered User
    Join Date
    04-28-2004
    Posts
    20

    Question macro code to change file-opening password

    i have created a testing tool which is meant for administering a test containing multiple-choice questions.

    the test-taker is given a copy of the file, and a password (say, "open_sesame", without the quotes) which allows him to start the test. after he has completed the test, he needs to click a button which runs a macro that saves and closes the file.

    I also want this macro to change the password (from "sesame" to the contents of cell A1 in Sheet1) before it is saved and closed.

    the idea is to make the file unusable a second time, becasue the test-taker would not know password to start the test once it has been re-set.

    can you help me with the macro code for re-setting the password. thanks.
    Last edited by arunjoshi; 06-16-2005 at 03:18 AM. Reason: correction of typos

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning Arunjoshi

    This code should help:

    Sub Save1()
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:="C:\Book4.xls", Password:="password1"
    Application.DisplayAlerts = True
    Application.Quit
    End Sub

    When called this macro will save the file Book4.xls to the location C:\ with the password set as password1, irrespective of whether or not another password was set to the file. The Application.Quit command will then close Excel.

    HTH

    DominicB

+ 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