Hide VBA code in new workbook

Anonymous
2014-10-18T22:34:54+00:00

Hi,

I'd like to hide VBA code in new workbook.

I have Master workbook and this is protected by password.

When I protect the Master workbook, then the new workbook that I copy from Master workbook is protected too, but not VBA code in new workbook.

I can see view code when I click the Tab name on the bottom.

How can I hide the VBA or Macro in Developer Tab and View Code in Tab name on the bottom of excel?

What should I do for those buttons to be gray out?

I want to apply password in the Master workbook before making the new workbook because the new workbook from Master workbook can't be controlled by me.

Thanks

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Anonymous
2014-10-19T17:54:10+00:00

Hi Tobemaster,

Set mywb = Thisworkbook

Set NewWb = Activeworkbook

 fname = Application.GetSaveAsFilename

' long codes here

mywb.Save

NewWb.SaveAs fName,FileFormat:=FileFormatValue, CreateBackup:=False

I used above code.

Is this the wrong way?

If you create the NewWb  directly from the Master work book, then it will inherit the VBA protection which you  previously applied to the Master workbook. As an example, if the new workbook (destWB) is created as shown in the following code, then it will inherit the VBA protection status of the Master workbook (srcWB):

'=========>>

Option Explicit

'--------->>

Public Sub Tester()

    Dim srcWB As Workbook, destWB As Workbook

    Dim sFilename As String, sStr As String

    Const sPath As String = "**C:\MyFolder**"                                  '<<=== Change

    Const srcWbName As String = "ToBeMaster.xlsm"                 '<<=== Change

    Const destWbName As String = "Distribution.xlsm"              '<<=== Change

    Set srcWB = Workbooks(srcWbName)

    sStr = Application.PathSeparator

    If Right(sPath, 1) = sStr Then

        sFilename = sPath & destWbName

    Else

        sFilename = sPath & sStr & destWbName

    End If

    srcWB.SaveCopyAs (sFilename)

    Set destWB = Workbooks.Open(sFilename)

    With destWB

        '\ your code

        .Close SaveChanges:=True

    End With

End Sub

'<<=========

If, however, the NewWb already exists and was not created in analogous manner from the Master workbook, then you will have to open it and apply the VBA protection manually as shown by Hans. 

===

Regards,

Norman

Was this answer helpful?

0 comments No comments

37 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Anonymous
    2014-10-19T01:46:30+00:00

    Thanks,

    I tried what Hans said , but not VBA code.

    The new workbook is protected by the same password, but I can still see VBA code in the new workbook.

    Thanks

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2014-10-19T01:31:25+00:00

    Hi Tobemaster,

    But I wonder if it is possible that I can protect new workbook's VBA code.

    I am making a new workbook from Master workbook.

    I copy some sheets and make new workbook and then, paste these sheets in.

    I can protect the Master workbook's VBA like above, but I wonder I can protect the new workbook too.

    If someone see the code and plays with codes, the new workbook will not be working.

    I will send this new workbook to someone , so I cannot manually enter the password in the new workbook.

    If you create the distributed workbook from a copy of the Master workbook then, as indicated by Hans, this workbook will inherit the protection of the Master. In this case, the VBA code in the distributed workbook will be protected with the same password which you have employed for the Master.

    ===

    Regards,

    Norman

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2014-10-18T23:58:24+00:00

    Thank you so much for your help.

    But I wonder if it is possible that I can protect new workbook's VBA code.

    I am making a new workbook from Master workbook.

    I copy some sheets and make new workbook and then, paste these sheets in.

    I can protect the Master workbook's VBA like above, but I wonder I can protect the new workbook too.

    If someone see the code and plays with codes, the new workbook will not be working.

    I will send this new workbook to someone , so I cannot manually enter the password in the new workbook.

    Thanks

    Was this answer helpful?

    0 comments No comments