+ Reply to Thread
Results 1 to 1 of 1

Cant hide worksheets after macros to force users to enable macros

  1. #1
    Registered User
    Join Date
    06-13-2015
    Location
    Zimbabwe, Bulawayo
    MS-Off Ver
    2013
    Posts
    1

    Cant hide worksheets after macros to force users to enable macros

    I wanted to secure my excel workbook, i used the hard disk serial number, and used the forge user to enable macros vba. Before i had some hidden worksheets which i don't want users to see, but when one enables the macros, all my hidden worksheets are no-longer hidden, even if i hide them, when i save, they re appear, even if i use the verryhidden option.

    The other problem is that after this vba when the workbook is opened in excel 2007, all password protected worksheets can be unprotected without a password.

    here is the code that i used

    Option Explicit
    Const WelcomePage = "Macros"
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    'Macro Purpose: Ensure that the macro instruction sheet is saved as the only
    ' visible worksheet in the workbook
    Dim ws As Worksheet
    Dim wsActive As Worksheet
    Dim vFilename As Variant
    Dim bSaved As Boolean
    'Turn off screen flashing
    With Application
    .EnableEvents = False
    .ScreenUpdating = False
    End With
    'Record active worksheet
    Set wsActive = ActiveSheet
    'Save workbook directly or prompt for saveas filename
    If SaveAsUI = True Then
    vFilename = Application.GetSaveAsFilename( _
    fileFilter:="Excel Files (*.xlsm), *.xlsm")
    If CStr(vFilename) = "False" Then
    bSaved = False
    Else
    'Save the workbook using the supplied filename
    Call HideAllSheets
    On Error Resume Next
    ThisWorkbook.SaveAs vFilename, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    Select Case Err.Number
    Case Is = 1004
    'User opted not to overwrite
    Case Else
    MsgBox "Unknown error, file not saved."
    bSaved = False
    GoTo ExitPoint
    End Select
    On Error GoTo 0

    'Add file to most recent files list
    Application.RecentFiles.Add vFilename
    Call ShowAllSheets
    bSaved = True
    End If
    Else
    'Save the workbook
    Call HideAllSheets
    ThisWorkbook.Save
    Call ShowAllSheets
    bSaved = True
    End If
    ExitPoint:
    'Restore file to where user was
    wsActive.Activate
    'Restore screen updates
    With Application
    .ScreenUpdating = True
    .EnableEvents = True
    End With

    'Set application states appropriately
    If bSaved Then
    ThisWorkbook.Saved = True
    Cancel = True
    Else
    Cancel = True
    End If
    End Sub

    Private Sub Workbook_Open()
    'Macro Purpose: Unhide all worksheets since macros are enabled
    Application.ScreenUpdating = False
    Call ShowAllSheets
    Application.ScreenUpdating = True
    ThisWorkbook.Saved = True
    End Sub

    Private Sub HideAllSheets()
    'Macro Purpose: 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()
    'Macro Purpose: 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
    Dim oFSO As Object
    Dim drive As Object

    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set drive = oFSO.GetDrive("C:\")
    ActiveSheet.Range("A1").Value = drive.SerialNumber

    Set oFSO = Nothing
    Set drive = Nothing
    'release memory
    End Sub

    i combined the HHD serial and force macros vba
    where did i go wrong

    coz i also want to use some of the worksheets to be hidden based on values of certain cells, but that is no-longer possible, as the worksheets are shown hidden as soon as one saves the workbook
    Last edited by Mboemoyo85; 06-13-2015 at 03:07 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help with my force enable macros code being autosaved
    By mmazz365 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-04-2015, 11:39 AM
  2. Force Enable Macros with Password on Save
    By simmo86 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-25-2010, 11:30 AM
  3. force enable macros lag
    By FRIEL in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-07-2009, 02:13 PM
  4. [SOLVED] Force to enable macros
    By Denys in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2006, 09:30 AM
  5. How can force enable macros to be able to open my workbook?
    By kcdonaldson in forum Excel General
    Replies: 3
    Last Post: 12-05-2005, 02:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

X vBulletin 4.1.8 Debug Information

  • Page Generation 0.05170 seconds
  • Memory Usage 8,874KB
  • Queries Executed 15 (?)
More Information
Template Usage (32):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)footer
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (1)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (4)navbar_noticebit
  • (6)option
  • (1)postbit_legacy
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (4)showthread_bookmarksite
  • (5)showthread_similarthreadbit
  • (1)showthread_similarthreads
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper
  • (1)vbseo_linkbackmenu_entry 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (39):
  • ./vbseo.php
  • ./env.php
  • ./vbseo/includes/functions_vbseo.php
  • ./vbseo/includes/functions_vbseo_pre.php
  • ./vbseo/includes/functions_vbseo_url.php
  • ./vbseo/includes/functions_vbseo_createurl.php
  • ./vbseo/includes/functions_vbseo_db.php
  • ./vbseo/includes/functions_vbseo_vb.php
  • ./vbseo/includes/functions_vbseo_seo.php
  • ./vbseo/includes/functions_vbseo_misc.php
  • ./vbseo/includes/functions_vbseo_crr.php
  • ./vbseo/includes/functions_vbseo_cache.php
  • ./vbseo/includes/functions_vbseo_hook.php
  • ./vbseo/includes/functions_vbseo_startup.php
  • ./includes/config.php
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/functions.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/functions_cforum.php
  • ./includes/functions_facebook.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (48):
  • init_startup
  • friendlyurl_resolve_class
  • database_pre_fetch_array
  • database_post_fetch_array
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • fetch_musername
  • cache_templates
  • template_register_var
  • parse_templates
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • reputation_image
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • showthread_similarthread_query
  • showthread_similarthreadbit
  • forumrules
  • showthread_bookmarkbit
  • navbits
  • navbits_complete
  • showthread_complete


Search Engine Friendly URLs by vBSEO 3.6.0 RC 1