How to Prevent Access with Disabled Macros?

Asked

Viewed 373 times

1

I have a registration form that shows up as soon as we open the spreadsheet. The registration list (in the Sheets) is invisible and can be accessed only by password by clicking on the "Database" button. However, when a person will access it for the first time on his machine, appears the Excel warning to enable macros, and the contents of the spreadsheet (in Sheets) ends up being exposed to the user. I would like only a warning sheet to appear, in order to open the form only if it enables the macros first. I already created it with the guidelines and I left it in Veryhidden, but I wanted to know what would be the code to put in Thisworkbook. I think it would be in Workbook_beforeclose.

Someone would know to help?

  • Hello colleague, welcome to the SOPT. This site is not a forum. If not done yet, do the [tour], but mainly do not miss read [Ask]. Your question is not entirely clear. It seems that you say that the form is displayed even if the user does not enable macros (which I find unlikely, since without macros enabled the form code does not perform). About exposing contents of spreadsheets (Sheets), isn’t it just a matter of putting password in Excel file? Finally, explain your problem better, illustrate with some image and, if possible, prepare a [mcve] to help understanding.

  • Thanks for the return Luiz. I wish I could put pictures, but I still don’t have that permission. What I mean is that when the user opens the file, the content is exposed until it enables macros. I don’t want this to happen. That’s why I created a warning sheet and I want only it to be exposed, while the ones that contain the data are hidden, when he opens the spreadsheet for the first time. There is a way to do this by code. This link ( is in English) explains my situation. http://www.cpearson.com/excel/EnableMacros.aspx. I’m trying to adapt to my reality

  • Not at all, Granado. Well, even then you could have edited the question to make some points clearer, even put the link you are trying to play.

1 answer

0

got!!!!

My code went like this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

  'Passo 1: Declarando variáveis

  'Dim ws As Worksheet

  'Passo 2: Deixa visível a Sheet inicial

  'Sheets("Alerta").Visible = xlSheetVisible

  'Passo 3: Inicia looping em todas as worksheets

  'For Each ws In ThisWorkbook.Worksheets

  'Passo 4: Checa o nome de cada Worksheet

  'If ws.Name <> "Alerta" Then

  'Passo 5: Esconde a Sheet

  'ws.Visible = xlVeryHidden

  End If

  'Passo 6: Loop na próxima Worksheet

  'Next ws

  'Passo 7: Salva a planilha

  'ThisWorkbook.Save

End Sub

Private Sub Workbook_Open()

  'Passo 1: Declarando variáveis

  'Dim ws As Worksheet

  'Passo 2: Inicia looping em todas as worksheets

  'For Each ws In ThisWorkbook.Worksheets

  'Passo 3: Mostra todas as Sheets

  'ws.Visible = xlSheetVisible

  'Passo 4: Loop na próxima Wworksheet

  'Next ws

  'Passo 5: Esconde todas as Sheets

  'Application.Visible = False

  'Passo 6: Mostra apenas o Formulário de Cadastro ao abrir a Workbook

  'FormulárioReserva.Show


End Sub

Thank you for your attention!!!!! :)

  • It’s a good thing you were able to solve it. Better yet you bothered to answer it yourself! : ) Only two details: 1) the code is all commented on. It is good to leave the code functional, so it can be useful for another person in the future. 2) It would be good to also explain a little how it works. In your case, the explanation is in comments, so it is more ok. But perhaps the understanding becomes clearer when you improve a little the question. After making some of these changes, let me know that I give you my +1. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.