+ Reply to Thread
Results 1 to 3 of 3

Auto Copy Macro?

  1. #1
    Henry
    Guest

    Auto Copy Macro?

    Hi,

    I have an macro that would protect the sheet and allow insert/delete columns
    and rows, as follow,

    Sub Auto_Open()
    With Worksheets("Sheet 1")
    .Protect Password:="hi", userinterfaceonly:=True
    .EnableOutlining = True
    End With

    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
    False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
    AllowFormattingRows:=True, AllowInsertingColumns:=True,
    AllowInsertingRows _
    :=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
    AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
    AllowUsingPivotTables:=True

    End Sub

    i would like to modify it so that when i duplicate "Sheet 1" to "Sheet 2",
    "Sheet 3", Sheet 4".....and so on, the macro would still work on all sheets
    that start with "Sheet", any idea?

    Thanks

  2. #2
    Dave Peterson
    Guest

    Re: Auto Copy Macro?

    Option Explicit
    Sub Auto_Open()
    Dim wks As Worksheet

    For Each wks In ThisWorkbook.Worksheets
    If LCase(Left(wks.Name, 5)) = "sheet" Then
    With wks
    .Protect Password:="hi", userinterfaceonly:=True
    .EnableOutlining = True
    End With
    End If
    Next wks

    End Sub

    If you wanted all those other protection options:

    Option Explicit
    Sub Auto_Open()
    Dim wks As Worksheet

    For Each wks In ThisWorkbook.Worksheets
    If LCase(Left(wks.Name, 5)) = "sheet" Then
    With wks
    .Protect Password:="hi", userinterfaceonly:=True, _
    DrawingObjects:=False, Contents:=True, _
    Scenarios:=False, AllowFormattingCells:=True, _
    AllowFormattingColumns:=True, AllowFormattingRows:=True, _
    AllowInsertingColumns:=True, AllowInsertingRows:=True, _
    AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True,
    _
    AllowDeletingRows:=True, AllowSorting:=True, _
    AllowFiltering:=True, AllowUsingPivotTables:=True
    .EnableOutlining = True
    End With
    End If
    Next wks

    End Sub



    Henry wrote:
    >
    > Hi,
    >
    > I have an macro that would protect the sheet and allow insert/delete columns
    > and rows, as follow,
    >
    > Sub Auto_Open()
    > With Worksheets("Sheet 1")
    > .Protect Password:="hi", userinterfaceonly:=True
    > .EnableOutlining = True
    > End With
    >
    > ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
    > False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
    > AllowFormattingRows:=True, AllowInsertingColumns:=True,
    > AllowInsertingRows _
    > :=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
    > AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
    > AllowUsingPivotTables:=True
    >
    > End Sub
    >
    > i would like to modify it so that when i duplicate "Sheet 1" to "Sheet 2",
    > "Sheet 3", Sheet 4".....and so on, the macro would still work on all sheets
    > that start with "Sheet", any idea?
    >
    > Thanks


    --

    Dave Peterson

  3. #3
    Dave Peterson
    Guest

    Re: Auto Copy Macro?

    Watch out for line wrap on that second sample.

    Dave Peterson wrote:
    >
    > Option Explicit
    > Sub Auto_Open()
    > Dim wks As Worksheet
    >
    > For Each wks In ThisWorkbook.Worksheets
    > If LCase(Left(wks.Name, 5)) = "sheet" Then
    > With wks
    > .Protect Password:="hi", userinterfaceonly:=True
    > .EnableOutlining = True
    > End With
    > End If
    > Next wks
    >
    > End Sub
    >
    > If you wanted all those other protection options:
    >
    > Option Explicit
    > Sub Auto_Open()
    > Dim wks As Worksheet
    >
    > For Each wks In ThisWorkbook.Worksheets
    > If LCase(Left(wks.Name, 5)) = "sheet" Then
    > With wks
    > .Protect Password:="hi", userinterfaceonly:=True, _
    > DrawingObjects:=False, Contents:=True, _
    > Scenarios:=False, AllowFormattingCells:=True, _
    > AllowFormattingColumns:=True, AllowFormattingRows:=True, _
    > AllowInsertingColumns:=True, AllowInsertingRows:=True, _
    > AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True,
    > _
    > AllowDeletingRows:=True, AllowSorting:=True, _
    > AllowFiltering:=True, AllowUsingPivotTables:=True
    > .EnableOutlining = True
    > End With
    > End If
    > Next wks
    >
    > End Sub
    >
    > Henry wrote:
    > >
    > > Hi,
    > >
    > > I have an macro that would protect the sheet and allow insert/delete columns
    > > and rows, as follow,
    > >
    > > Sub Auto_Open()
    > > With Worksheets("Sheet 1")
    > > .Protect Password:="hi", userinterfaceonly:=True
    > > .EnableOutlining = True
    > > End With
    > >
    > > ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
    > > False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
    > > AllowFormattingRows:=True, AllowInsertingColumns:=True,
    > > AllowInsertingRows _
    > > :=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
    > > AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
    > > AllowUsingPivotTables:=True
    > >
    > > End Sub
    > >
    > > i would like to modify it so that when i duplicate "Sheet 1" to "Sheet 2",
    > > "Sheet 3", Sheet 4".....and so on, the macro would still work on all sheets
    > > that start with "Sheet", any idea?
    > >
    > > Thanks

    >
    > --
    >
    > Dave Peterson


    --

    Dave Peterson

+ 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