Consulting

Results 1 to 4 of 4

Thread: Save file and a standalone read-only version

  1. #1
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location

    Save file and a standalone read-only version

    Hi all

    I have a workbook that I need to save using VBA in two ways. The first is the default type of save, the second is to save a read only copy of the file but in a different location.

    The VBA code I am looking for would do something like:
    1) save the current file
    2) save a read only version

    but after the first use this would become
    1) save the current file
    2) Switch off the read-only in the other closed file
    2) Save the contents of the current file over it
    4) Reapply the read-only

    Is this something you could help with?

  2. #2
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    This takes me quite far.

    How do I remove the option of the file being read-only when it opens?

    Application.DisplayAlerts = False
        ChDir "C:\Documents and Settings\sassora\Desktop"
        ActiveWorkbook.SaveAs Filename:= _
        "C:\Documents and Settings\sassora\Desktop\testdoc.xls", FileFormat:=xlNormal _
        , Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
        CreateBackup:=False
        ActiveWorkbook.SaveAs Filename:= _
        "C:\Documents and Settings\sassora\Desktop\testdoc2.xls", FileFormat:=xlNormal _
        , Password:="", WriteResPassword:="", ReadOnlyRecommended:=True, _
        CreateBackup:=False
    Application.DisplayAlerts = True

  3. #3
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    Is this a better way of making the file read only, I am using xl2003 and xl2010.

    http://www.mrexcel.com/forum/showthr...e-as-Read-Only

  4. #4
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    After some dabbling, the following seems to do the trick.

    Sub SaveFiles()
        Const PathWorkList As String = "F:\fun.xls"
        Const PathWorkListReadOnly As String = "F:\fun (for browsing).xls"
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs Filename:=PathWorkList
        On Error Resume Next
        VBA.SetAttr PathWorkListReadOnly, vbNormal
        ActiveWorkbook.SaveAs Filename:=PathWorkListReadOnly
        ActiveWorkbook.SaveAs Filename:=PathWorkList
        VBA.SetAttr PathWorkListReadOnly, vbReadOnly
        Application.DisplayAlerts = True
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •