+ Reply to Thread
Results 1 to 7 of 7

VBA: saving workbook with password error

Hybrid View

Broobi VBA: saving workbook with... 10-08-2015, 07:16 AM
Kenneth Hobson Re: VBA: saving workbook with... 10-08-2015, 08:26 AM
Broobi Re: VBA: saving workbook with... 10-08-2015, 08:35 AM
Kenneth Hobson Re: VBA: saving workbook with... 10-08-2015, 09:14 AM
Broobi Re: VBA: saving workbook with... 10-08-2015, 10:12 AM
Kenneth Hobson Re: VBA: saving workbook with... 10-08-2015, 10:22 AM
Broobi Re: VBA: saving workbook with... 10-08-2015, 10:25 AM
  1. #1
    Registered User
    Join Date
    03-12-2014
    Location
    Windsor, UK
    MS-Off Ver
    Excel 2007
    Posts
    43

    VBA: saving workbook with password error

    Hi All

    Hoping someone can help me out with an error i'm getting with this bit of code please

    When i try to run this code i get a "Named Arugument Not Found"

    
    
    
    Dim filepath2 As String
    Dim Filename3 As String
    
    filepath2 = "H:\Monthly MI\Excel_Suites\"
    Filename3 = CBfile & " v1" & ".xlsm"
    cbpass = "RRRP"
    
    ActiveWorkbook.SaveCopyAs Filename:=filepath2 & Filename3, Password:=cbpass
    Any help is greatly appreitated

    My thanks in advance!
    Last edited by Broobi; 10-08-2015 at 10:28 AM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA: saving workbook with password error

    Where did you set the value of CBFile? It is not even dimmed.

  3. #3
    Registered User
    Join Date
    03-12-2014
    Location
    Windsor, UK
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: VBA: saving workbook with password error

    Sorry!! forgot that bit... see below (my knowledge of VBA isn't great I'm afraid!)

    
    Dim filepath2 As String
    Dim Filename3 As String
    Dim CBfile As String
    Dim CB As String
    Dim file_date As Date
    
    file_date = Date
    CB = "RRRP"
    CBfile = "MyWORK " & Format(file_date, "mmm-yyyy ") & CB
    filepath2 = "H:\Monthly MI\Excel_Suites\"
    Filename3 = CBfile & " v1" & ".xlsm"
    cbpass = "RRRP"
    
    ActiveWorkbook.SaveCopyAs Filename:=filepath2 & Filename3, Password:=cbpass

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA: saving workbook with password error

    If you want to change the password, then save your master file with the password, do your thing, and then change the master file's password to something else. As Compile will show you, SaveCopyAs only has one input parameter.

    Tip: Debug.Print can be a good debugging tool to show results in the Immediate window after a run. e.g.
    Sub ken()
      Dim filepath2 As String, Filename3 As String, CBfile As String, CB As String
      Dim file_date As Date, cbpass As String
      
      file_date = Date
      CB = "RRRP"
      CBfile = "MyWORK " & Format(file_date, "mmm-yyyy ") & CB
      filepath2 = "H:\Monthly MI\Excel_Suites\"
      'filepath2 = "c:\t\"
      Filename3 = CBfile & " v1" & ".xlsm"
      cbpass = "RRRP"
      
      Debug.Print filepath2 & Filename3
      
      ActiveWorkbook.SaveCopyAs filepath2 & Filename3
    End Sub

  5. #5
    Registered User
    Join Date
    03-12-2014
    Location
    Windsor, UK
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: VBA: saving workbook with password error

    Hi Ken

    Thanks for the reply

    Looking at your suggestion, I can't see where the value of cbpass is applied to the workbook as the password when saving it? am I missing something?

    would something like...

    ActiveWorkbook.SaveAs filepath2 & Filename3, xlOpenXMLWorkbook, password:=cbpass
    work better?

    Many thanks
    Last edited by Broobi; 10-08-2015 at 10:14 AM.

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA: saving workbook with password error

    That will add the password which can be different than the master file's password. Saving a Copy As is fast and leaves your master file still open. The solution depends on what your goals are.

  7. #7
    Registered User
    Join Date
    03-12-2014
    Location
    Windsor, UK
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: VBA: saving workbook with password error

    Hi Ken

    got it!

    SO like you said, i changed it to SaveAs added in and it worked great! :D

    Thank your for your help on this, was really appretiated!

    for other peoples ref my final code was:

    Dim filepath2 As String
    Dim Filename3 As String
    Dim CBfile As String
    Dim CB As String
    Dim file_date As Date
    Dim cbpass As String
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    
    file_date = Date
    CB = "RRRP"
    CBfile = "MyWORK " & Format(file_date, "mmm-yyyy ") & CB
    filepath2 = "c:\"
    Filename3 = CBfile & " v1" & ".xlsm"
    cbpass = "RRRP123"
    
    ActiveWorkbook.SaveAs Filename:=filepath2 & Filename3, Password:=cbpass

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Remove Workbook Password when Saving a Copy for Distribution
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2015, 04:51 AM
  2. Creating a new workbook, copying sheets & saving workbook - Subscript error
    By amphinomos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2014, 09:04 AM
  3. Error 9 when saving workbook
    By 06nenglish in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-06-2013, 10:47 AM
  4. [SOLVED] password protect worksheets upon opening or saving a workbook.
    By emilyloz in forum Excel General
    Replies: 2
    Last Post: 06-14-2013, 03:14 PM
  5. VBA Run Time Error when saving workbook between Users....?
    By slu2383 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 12-28-2012, 04:22 PM
  6. Error Saving Protected Workbook
    By sdforson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2010, 10:44 AM
  7. HELP! Get error while saving after password protection
    By monica in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2005, 06:35 PM

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