• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to make the user to enable macros and Enter the mandatory fields

My excel has one tab where the user needs to fill the mandatory fields, if he missed excel will give the pop up and will not allow to close until the fields are populated. now they asked me what to do in case if the user has disabled the macros. How to make someone enable to macro and then enter all required fields. Both codes are not working at the same time. Kindly help asap. I have a target to complete it by tomorrow.
 
Hi, Nithya Srivatsan!

Here are some tips to prevent the updating of a book with the macros disabled.

- add a dummy worksheet with text indicating that the book cannot be updated if macros are disabled

- password protect all the worksheets and the workbook structure

- before exiting the workbook (and before updating) hide all worksheets except dummy, then save & exit

- in dummy place a command button that performs the unhiding/showing of the rest of the worksheets when pressed (so it'll only work if macros are enabled)

- don't let the user protect or unprotect individual worksheets manually, if needed add a button to each one to protect/unprotect

- before saving, check that all the worksheets have been protected with the correct password

Hope it aids.

Regards!
 
Thank you very much for your immediate response, however the hiding or un hiding works but not the code for mandatory field updated. Should I update the macro in the sheet or in this workbook. How can I send the file that I have to you?
 
Hi Nithya,


Regarding your second question, read the post


http://chandoo.org/forums/topic/posting-a-sample-workbook


Regards,

Prasad DN
 
I found a code that will force users to enable macros to access a document if they don't accept enable macro's this would give them no choice in the matter and it won't allow access to the complete document.


I am not sure what the protocol is for offering advice, since I have never had anything to offer when I started viewing this website...


The "EXPERTS" will have to "REVIEW THE CODE AND APROVE THE USE" for your success... Anyone want to jump in and test and approve please go for it. I don't know how to do that stuff.. YET!!! ;)


Here's the code Force Users Enable Macro's...


-VBA-

Option Explicit

Const WelcomePage = "Macros"

Private Sub Workbook_BeforeClose(Cancel As Boolean)

'Turn off events to prevent unwanted loops

Application.EnableEvents = False

'Evaluate if workbook is saved and emulate default prompts

With ThisWorkbook

If Not .Saved Then

Select Case MsgBox("Do you want to save the changes you made to '" & .Name & "'?", _

vbYesNoCancel + vbExclamation)

Case Is = vbYes

'Call customized save routine

Call CustomSave

Case Is = vbNo

'Do not save

Case Is = vbCancel

'Set up procedure to cancel close

Cancel = True

End Select

End If

'If Cancel was clicked, turn events back on and cancel close,

'otherwise close the workbook without saving further changes

If Not Cancel = True Then

.Saved = True

Application.EnableEvents = True

.Close savechanges:=False

Else

Application.EnableEvents = True

End If

End With

End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

'Turn off events to prevent unwanted loops

Application.EnableEvents = False

'Call customized save routine and set workbook's saved property to true

'(To cancel regular saving)

Call CustomSave(SaveAsUI)

Cancel = True

'Turn events back on an set saved property to true

Application.EnableEvents = True

ThisWorkbook.Saved = True

End Sub

Private Sub Workbook_Open()

'Unhide all worksheets

Application.ScreenUpdating = False

Call ShowAllSheets

Application.ScreenUpdating = True

End Sub

Private Sub CustomSave(Optional SaveAs As Boolean)

Dim ws As Worksheet, aWs As Worksheet, newFname As String

'Turn off screen flashing

Application.ScreenUpdating = False

'Record active worksheet

Set aWs = ActiveSheet

'Hide all sheets

Call HideAllSheets

'Save workbook directly or prompt for saveas filename

If SaveAs = True Then

newFname = Application.GetSaveAsFilename( _

fileFilter:="Excel Files (*.xls), *.xls")

If Not newFname = "False" Then ThisWorkbook.SaveAs newFname

Else

ThisWorkbook.Save

End If

'Restore file to where user was

Call ShowAllSheets
/>aWs.Activate

'Restore screen updates

Application.ScreenUpdating = True

End Sub

Private Sub HideAllSheets()

'Hide all worksheets except the macro welcome page

Dim ws As Worksheet

Worksheets(WelcomePage).Visible = xlSheetVisible

For Each ws In ThisWorkbook.Worksheets

If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVeryHidden

Next ws

Worksheets(WelcomePage).Activate

End Sub

Private Sub ShowAllSheets()

'Show all worksheets except the macro welcome page

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets

If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVisible

Next ws

Worksheets(WelcomePage).Visible = xlSheetVeryHidden

End Sub

I Just thought it would be nice to finally offer something back through my hours-upon-hours of sufing for answers to my personal questions and picking up future issue resolutions I may need.


Please Any Experts! let me know if this is unacceptable and only the experts can offer solutions.... I will cease... :)


Good Luck! Wait for Expert to TEST FIRST!!! I Hope it works... You may want to change the green screen to something else... Red/Yellow for warning/caution???
 
SMC, thank you for posting the VBA you found.


It is polite to reference the source of any code or techniques you copy. I also like to insert it into the VBA using the '

e.g.

Sub HelpingHands()

'Code partially copied from Chandoo.org

insert Code

End Sub
 
okay... I am not sure where I found it I have been collecting for a couple of years randomly... As for adding for a reference doc... I did not even know if it was functional so that's why I put it out there for Experts hands to figure out...


Thank you for your guidance... Once I know something has got the Green light I would love to add to reference... :)
 
This code works. I have tested it even before it was posted. I took it when I googled for similar information. but as i mentioned earlier I have two seperate codes both are functioning on this workbook page. if one code works the other doesn't. This is where is my problem.


First code: Enable Macros

Second Code: Fill all 17 columns out of 25


My question is I have two seperate codes for the first and second and where do I place them in the excel. I am not finding a place in this website to upload the excel along with the code that I have so that an expert can help me...
 
Thank you Prasad n. I found the link to upload the document.

https://docs.google.com/open?id=0BygqUhtDfTtZZmE2MmY3YjAtY2MwOS00OTE1LTg4YmUtOWNlYTYzNjY5Yjdj


Can someone help me with both codes to keep in same workbook.
 
Back
Top