If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > VB Coding in excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-02-09, 05:21
Saminap Saminap is offline
Registered User
 
Join Date: Feb 2009
Posts: 1
VB Coding in excel

Hi All,

Apologies if I have posted this thread incorrectly, I am a first time user and this is the first time I am posting a thread.

Problem:

I am trying to close an excel file but to do this I need to set a prompt that will ask the user if they have set a password to the sheet. If they answer no the file does not close which is fine, but I also need for the password screen to appear for the user to set a password(tools > options > security)
How do I do this?

This is the code I am using to prompt the user before close:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim Response As Long
Response = MsgBox("Have you set a password to this file?", vbYesNo)
If Response = vbNo Then
Cancel = True
End If

End Sub

Can I have help on this matter today please, need to complete and send out

Cheers

Sam
Reply With Quote
  #2 (permalink)  
Old 12-30-09, 04:51
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
Hi,

Add this line of code:
Code:
Application.Dialogs(xlDialogWorkbookProtect).Show
Hope that helps...
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On