+ Reply to Thread
Results 1 to 7 of 7

Protect with "SaveCopyAs"

  1. #1
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,167

    Protect with "SaveCopyAs"

    I am creating a work sheet to be "Saved as" another name, my problem is I wish to protect it at the time of the "save as".

    <snipet>
    Worksheets("sheet1").Select
    Sheets("Sheet1").Copy
    ActiveWorkbook.SaveCopyAs vFname 'vFname is new file name as Variant

    Any help is appreciated!
    Regards

    Rick
    Win10, Office 365

  2. #2
    Dave Peterson
    Guest

    Re: Protect with "SaveCopyAs"

    It looks like you're copying a single sheet from a workbook and saving that to a
    new workbook.

    If that's the case, drop the .savecopyas and use .saveas.

    Look at VBA's help for its syntax.

    Rick_Stanich wrote:
    >
    > I am creating a work sheet to be "Saved as" another name, my problem is
    > I wish to protect it at the time of the "save as".
    >
    > <snipet>
    > Worksheets("sheet1").Select
    > Sheets("Sheet1").Copy
    > ActiveWorkbook.SaveCopyAs vFname 'vFname is new file name as Variant
    >
    > Any help is appreciated!
    >
    > --
    > Rick_Stanich
    >
    > I am me
    > ------------------------------------------------------------------------
    > Rick_Stanich's Profile: http://www.excelforum.com/member.php...o&userid=28957
    > View this thread: http://www.excelforum.com/showthread...hreadid=527358


    --

    Dave Peterson

  3. #3
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,167
    That was the course of action I originally took, which caused a seperate problem.
    http://www.excelforum.com/showthread.php?t=512358
    SaveCopyAs was my work around.

  4. #4
    Dave Peterson
    Guest

    Re: Protect with "SaveCopyAs"

    If the code is in the activeworkbook, then one problem is that if you close the
    file with the code, then the macro stops at that point.

    So this won't get past the .close line:


    ActiveWorkbook.Close SaveChanges:=False 'Close new file
    'Open original file
    Workbooks.Open Filename:=sFname1

    You could use:
    dim wkbk as workbook
    set wkbk = activeworkbook
    Workbooks.Open Filename:=sFname1
    wkbk.close savechanges:=false


    Rick_Stanich wrote:
    >
    > That was the course of action I originally took, which caused a seperate
    > problem.
    > http://www.excelforum.com/showthread.php?t=512358
    > SaveCopyAs was my work around.
    >
    > --
    > Rick_Stanich
    >
    > I am me
    > ------------------------------------------------------------------------
    > Rick_Stanich's Profile: http://www.excelforum.com/member.php...o&userid=28957
    > View this thread: http://www.excelforum.com/showthread...hreadid=527358


    --

    Dave Peterson

  5. #5
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,167
    Thank you, I will give it a try!

  6. #6
    Dave Peterson
    Guest

    Re: Protect with "SaveCopyAs"

    Ps. Instead of using a variable, it looks like you could just use ThisWorkbook.

    Workbooks.Open Filename:=sFname1
    Thisworkbook.close savechanges:=false

    (But the order is still very important.)

    Dave Peterson wrote:
    >
    > If the code is in the activeworkbook, then one problem is that if you close the
    > file with the code, then the macro stops at that point.
    >
    > So this won't get past the .close line:
    >
    > ActiveWorkbook.Close SaveChanges:=False 'Close new file
    > 'Open original file
    > Workbooks.Open Filename:=sFname1
    >
    > You could use:
    > dim wkbk as workbook
    > set wkbk = activeworkbook
    > Workbooks.Open Filename:=sFname1
    > wkbk.close savechanges:=false
    >
    > Rick_Stanich wrote:
    > >
    > > That was the course of action I originally took, which caused a seperate
    > > problem.
    > > http://www.excelforum.com/showthread.php?t=512358
    > > SaveCopyAs was my work around.
    > >
    > > --
    > > Rick_Stanich
    > >
    > > I am me
    > > ------------------------------------------------------------------------
    > > Rick_Stanich's Profile: http://www.excelforum.com/member.php...o&userid=28957
    > > View this thread: http://www.excelforum.com/showthread...hreadid=527358

    >
    > --
    >
    > Dave Peterson


    --

    Dave Peterson

  7. #7
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,167
    File name will be changing constantly, hence the variable.

    As for protecting the new work sheets, I resorted to protecting the required sheets prior to "SaveCopyAs" then unprotect the originals after the operation has completed.

    Works ok for me.

    'new protect scheme
    Sheets("Sheet1").Select
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    ActiveSheet.EnableSelection = xlNoSelection

    'Do some code

    ActiveWorkbook.Close SaveChanges:=False 'Close new file
    Worksheets("sheet1").Select
    ActiveSheet.Unprotect ("****")

    'End VBA program

    Thanks again for your input!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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