Results 1 to 8 of 8

Active content error allowing unauthorised access to sheets

Threaded View

Throughstream Active content error allowing... 07-12-2019, 09:39 PM
AliGW Re: Active content 07-13-2019, 01:01 AM
Throughstream Re: Active content 07-13-2019, 01:24 AM
AliGW Re: Active content 07-13-2019, 01:28 AM
Throughstream Re: Active content 07-13-2019, 01:47 AM
AliGW Re: Active content 07-13-2019, 01:54 AM
Throughstream Re: Active content 07-13-2019, 02:07 AM
AliGW Re: Active content error... 07-13-2019, 02:09 AM
  1. #5
    Forum Contributor
    Join Date
    01-21-2017
    Location
    England
    MS-Off Ver
    2007
    Posts
    409

    Re: Active content

    Hi sorry I know it would make it easier but I wouldn't feel comfortable even producing a desensitised copy unless it was a last resort.

    Option Explicit
     
    Const WelcomePage = "View 2"
     
    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 propmts
        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)
         Dim newWB As Workbook
         Dim nameWB As String
         nameWB = ThisWorkbook.Name
         nameWB = Left(nameWB, Len(nameWB) - 4) & "xltx"
          '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
        
        ThisWorkbook.Saved = True
        
        Application.DisplayAlerts = False
        Sheet27.Cells.Copy
        Set newWB = Workbooks.Add
        With newWB
            .Sheets(1).Range("A1").PasteSpecial xlPasteValues
            .Sheets(1).Range("A1").PasteSpecial xlPasteFormats
            .Sheets(1).Range("A1").PasteSpecial xlPasteColumnWidths
            .Sheets(1).Range("A1").Select
            .Sheets(1).Name = "View 2"
            .Sheets(1).Protect Password = "abc"
           
            .SaveAs Filename:="D:\" & nameWB, FileFormat:= _
            xlOpenXMLTemplate
           .Close False
        End With
         Application.DisplayAlerts = True
         Application.EnableEvents = True
         
    End Sub
     
    Private Sub Workbook_Open()
         'Unhide all worksheets
        Application.ScreenUpdating = False
        Call ShowAllSheets
        Application.ScreenUpdating = True
        Sheet27.Activate
    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 (*.xlsm), *.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 = xlSheetHidden
        Next ws
         
        Worksheets(WelcomePage).Activate
        ActiveWindow.ScrollColumn = 1
    ActiveWindow.ScrollRow = 1
    End Sub
     
    Private Sub ShowAllSheets()
        Sheets("Rota").Visible = xlSheetVisible
            Sheets("Hours").Visible = xlSheetVisible
    
                                                    Sheets("View 2").Visible = xlSheetVisible
    
    End Sub
    Haha well I use 2007 at home and 2010 at work.

    The work book is saved as both a .xlsm and a .xlsx at the same time in two locations however it was doing the "active content error" before I started saving it as a .xlsx as well.

    Could it just be that the admin's at my work have made it so that it automatically disabled active content?
    Last edited by AliGW; 07-13-2019 at 01:51 AM. Reason: Code tags corrected.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Find active row and clear content in that row
    By a94andwi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2018, 10:26 AM
  2. [SOLVED] Active Content Disabled, shuts down excel when enabled
    By kriminaal in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-10-2018, 02:40 PM
  3. Active Content warning when ActiveWorkbook.FollowHyperlink is executed
    By JimDandy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-05-2017, 03:58 PM
  4. [SOLVED] BUG: formulas replaced by values when active content is enabled
    By mg.luis in forum Excel General
    Replies: 1
    Last Post: 12-18-2015, 11:56 AM
  5. Getting rid of active content in a file
    By Brian Drozd in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-22-2014, 05:27 PM
  6. [SOLVED] How to put content of active cell in variable?
    By obgle in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-20-2012, 02:08 PM
  7. Return to active sheet-cell content copy
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-09-2008, 11:26 AM

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1