A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
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