Q:

VBA: SaveCopyAs not password protecting

I have a template, that I copy data into, then suse SaveCopyAs to save it down in a different location. I want to start adding a it each time. However all that happens is it saves it down in new location without password.
Attached below is the code, the reason I use the extra (unnecessary) .Open is due to the fact I could not find a way to do it just using SaveCopyAs
Option Explicit 
Sub SaveCopyAs_password()

    Dim passdate As String
    Dim wb, wbresults As Workbook

    passdate = "hello"

    Workbooks.Open ("R:\Macros\pre\Mealplan.xlsx")

    Set wbresults = Workbooks("Mealplan")
    wbresults.SaveCopyAs ("R:\Macros\post\Mealplan.xlsx")

    Workbooks.Open ("R:\Macros\post\Mealplan.xlsx")
    Workbooks("Mealplan.xlsx").Activate

    Set wb = ActiveWorkbook
    ActiveWorkbook.SaveAs Password:=passdate

    wb.Close

End Sub

A:

This Simple code will work for you:
Sub SaveCopyAs_password()

    Dim passdate As String
    Dim wbresults As Workbook

    passdate = "hello"

    FileCopy "R:\Macros\pre\Mealplan.xlsx", "R:\Macros\post\Mealplan.xlsx"

    Set wbresults = Workbooks.Open("R:\Macros\post\Mealplan.xlsx")
    wbresults.SaveAs Password:=passdate

    wbresults.Close

End Sub

Another Way:
Sub SaveCopyAs_password()

    Dim passdate As String
    Dim wbresults As Workbook

    passdate = "hello"

    Set wbresults = Workbooks.Open("R:\Macros\pre\Mealplan.xlsx")

    wbresults.SaveAs Filename:="R:\Macros\post\Mealplan.xlsx", Password:=passdate

    wbresults.Close

End Sub

Run this Macro from any other workbook other than the 2 used in Macro.

