Password Protected Sheet

Protected SheetsMacroVBAAPIHide Columns
2 posts / 0 new
Last post
Alexander Artajaya 1 X 1
AA
Password Protected Sheet

Hi,

I have been working on a workbook that contains Macro for hiding columns with Modano active. 

I understand that Modano has password protection to prevent unwanted changes in the formula and formats but this has caused my code to break every time I re-open the workbook.

Is there any way to get around this without releasing the workbook?

Attached is a screenshot of the error that I got every time I run the code right after I open the workbook. 

Thanks

Attachments: 
Michael Hutchens A+ 189

Hi Alexander,

You need to use the Modano VBA API to safely manipulate content within sheets containing module components, including hiding and unhiding rows and columns. You cannot simply use normal VBA as this will cause the Modano meta data to diverge from the Excel file objects (e.g. Modano won't know you've hidden columns if you hide then using VBA without the Modano API) and ultimately corrupt your modular workbooks.

We've actually just updated the Modano API today to include the ability to hide and unhide columns within sheets containing module components within modular workbooks. To utilize this functionality, you will need to:

  1. Upgrade to at least version 10.4.4.0 if Modano (see www.modano.com/software/updates).
  2. Download the latest version of the Modano API (using this download link: http://www.modano.com/api/latest).
  3. Open your modular workbook in Excel.
  4. Open the Modano API in Excel and follow the instructions within its sheet to import the Modano API VBA code into your modular workbook. You can import some or all of the example modules but I usually just copy and paste code from the Modano API modules that I need. As long as you import all the API classes (which the import tool will do) you'll be ok.
  5. Add API-based code to your VBA routines to hide/unhide columns.

In your case, the example macro named 'Hide_Selected_Columns' in the module 'mExamplesColumns' demonstrates how to hide columns within sheets containing module components in modular workbooks using the 'SheetColumnSettingsUpdated' function within the ModanoApplication class. Here's the example macro code:

Sub Hide_Selected_Columns()
    
    'Demonstrates the automated hiding/unhiding of columns.
    
    'Private declarations:
    Dim fContinue As Boolean
    Dim strErrorMessage As String
    Dim modappConnection As New ModanoApplication
    Dim fColumnVisibilitySet As Boolean
    
    'Checks for valid connection:
    fContinue = modappConnection.ValidConnection(Nothing, False)
    
    'Hides the selected module component rows:
    If fContinue Then
        fColumnVisibilitySet = modappConnection.SheetColumnSettingsUpdated(Application.Selection, ColumnSpanProcedureHide)
    End If
    
    'Returns:
    Call MsgBox("Columns hidden = " & fColumnVisibilitySet)

End Sub

In your code, all the really need to do is add this to the start of your code:

Dim modappConnection As New ModanoApplication

And then whenever you want to hide columns call the SheetColumnSettingsUpdated function from within this class instead of using the normal VBA Range.EntireColumn.Hidden = False, as follows:

Call modappConnection.SheetColumnSettingsUpdated(Application.Selection, ColumnSpanProcedureHide)

I'm aware this all seems very complicated but it's actually very easy to import the Modano API classes and do all sorts of things to module content. I'd recommend playing with the example macros throughout the modules in the API and getting your head around it, after which it should all become much clearer.

If you're still struggling I'd recommend buying a support credit via the Support section of your Modano account (www.modano.com/account/support) and one of the Modano team can walk you through it.

Godspeed. M,