1

I want to design VBA code that protects excel document with password.

I know its possible with excel tools and its more secure, but I want to try this and use it in other projects.

I wrote this code

vPass = InputBox("Password : ")
If StrComp(vPass, "predefinedPass") <> 0 Then Application.Quit

But when I put it in Workbook_Open, the content of the file is still showing while while waiting for user to give password.

I don't want the content of file to be shown.

Any ideas??

12
  • 3
    Of course this won't protect the workbook as any user can open the workbook with macros disabled. Commented Jun 19, 2013 at 11:56
  • How to open workbook with macros disabled. and how to prevent user from doing that?? Commented Jun 19, 2013 at 12:17
  • 1
    @OuldAbba You don't put simply, Excel has a built in option to secure a file with a password, is there some reason why that wouldn't be suitable? Commented Jun 19, 2013 at 12:46
  • I know it has security option, and i know it 'perfect'. But I wanted this so i can run some actions before user can access the document. And now it OK. Commented Jun 19, 2013 at 14:26
  • 1
    "How to open workbook with macros disabled" - if a user configures macro security in Excel to anything other than "Low", then as a minimum he will be prompted to run macros or not. There's no way to prevent this: google for "open workbook without running macro" Commented Jun 20, 2013 at 5:46

1 Answer 1

1

It is simple before firing the event set

    Application.Screenupdating = False

once the condition is true set screenupdating back to true

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that does the job. But i also had to use Workbooks("myWorkbook"). Close before Application.Quit to completely make the content disappear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.