Force Macros to be Enabled
A common question on Excel newsgroups and forums is 'Can I prevent the macro warning from appearing when you open a workbook that contains macros?'. The simple answer is 'No!'. If you could disable macros using VBA code then it would be very easy for a virus writer to override Office's security settings and take control of your system.
However, you can use the technique described below to only let users make use of your workbook if macros are enabled - I have yet to find a more satisfactory alternative. There is an example file at the bottom of this page.
· In your workbook add a sheet and call it Macros Disabled or something similar. On this sheet put in a warning that the user must enable macros if they wish to use your workbook.
Пример:
· Open the Visual Basic Editor (Alt F11). In the project explorer double-click the ThisWorkbook icon (see here if you're not sure of how to do this). Paste this code. Note: if you named your sheet something other than 'Macros Disabled', you must change the code below to reflect that name.That's all you need to do. The code is fairly straightforward but is fairly effective.
- Код: Выделить всё
Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
End Sub
Private Sub Workbook_Open()
UnhideSheets
End Sub
Private Sub HideSheets()
Dim sht As Object
Application.ScreenUpdating = False
ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVisible
For Each sht In ThisWorkbook.Sheets
If sht.Name <> "Macros Disabled" Then sht.Visible = xlSheetVeryHidden
Next sht
Application.ScreenUpdating = True
ThisWorkbook.Save
End Sub
Private Sub UnhideSheets()
Dim sht As Object
Application.ScreenUpdating = False
For Each sht In ThisWorkbook.Sheets
sht.Visible = xlSheetVisible
Next sht
ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVeryHidden
Application.ScreenUpdating = True
End Sub
По-моему выше указанный принцип как раз то, что нужно для этого вопроса.1. Андрей Васюта писал(а):...или может можно как то програмно запретить запрос отключения макросов ...
2. Андрей Васюта писал(а):...может кто знает как в Экселе запретить комбинации клавиш (Ctrl+P и Ctrl+C)
Sub PPP()
Application.OnKey "^{c}", ""
Application.OnKey "^{p}", ""
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 66