+ Reply to Thread
Results 1 to 3 of 3

Protecting mailed worksheet

  1. #1
    Registered User
    Join Date
    02-26-2006
    Posts
    68

    Protecting mailed worksheet

    Is there a way to do this with code to lock the sheet that is created here which is to e-mailed in this macro? I know I van protect the original however I would like the e-mailed copy only protected.


    PROTECTION SOMEWHERE HERE:
    Sub Mail_Range()
    Dim source As Range
    Dim dest As Workbook
    Dim strdate As String

    Set source = Nothing
    On Error Resume Next
    Set source = Range("A1:J100").SpecialCells(xlCellTypeVisible)
    On Error GoTo 0
    If source Is Nothing Then
    MsgBox "The source is not a range or the sheet is protect, please correct and try again.", vbOKOnly
    Exit Sub
    End If

    Application.ScreenUpdating = False
    Set dest = Workbooks.Add(xlWBATWorksheet)
    source.Copy
    With dest.Sheets(1)
    .Cells(1).PasteSpecial Paste:=8
    ' Paste:=8 will copy the column width in Excel 2000 and higher
    ' If you use Excel 97 use the other example
    .Cells(1).PasteSpecial xlPasteValues, , False, False
    .Cells(1).PasteSpecial xlPasteFormats, , False, False
    .Cells(1).Select
    Application.CutCopyMode = False
    End With

    strdate = Format(Now, "dd-mm-yy h-mm-ss")
    With dest
    .SaveAs "Selection of " & ThisWorkbook.Name _
    & " " & strdate & ".xls"
    .SendMail "", "This is the Subject line"
    .ChangeFileAccess xlReadOnly
    Kill .FullName
    .Close False
    End With
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Ron de Bruin
    Guest

    Re: Protecting mailed worksheet

    hi parteegolfer

    Before you save it protect the worksheet

    With dest
    ..Sheets(1).Protect "Ron"
    ..SaveAs "Selection of " & ThisWorkbook.Name _
    & " " & strdate & ".xls"


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "parteegolfer" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Is there a way to do this with code to lock the sheet that is created
    > here which is to e-mailed in this macro? I know I van protect the
    > original however I would like the e-mailed copy only protected.
    >
    >
    > PROTECTION SOMEWHERE HERE:
    > Sub Mail_Range()
    > Dim source As Range
    > Dim dest As Workbook
    > Dim strdate As String
    >
    > Set source = Nothing
    > On Error Resume Next
    > Set source = Range("A1:J100").SpecialCells(xlCellTypeVisible)
    > On Error GoTo 0
    > If source Is Nothing Then
    > MsgBox "The source is not a range or the sheet is protect, please
    > correct and try again.", vbOKOnly
    > Exit Sub
    > End If
    >
    > Application.ScreenUpdating = False
    > Set dest = Workbooks.Add(xlWBATWorksheet)
    > source.Copy
    > With dest.Sheets(1)
    > Cells(1).PasteSpecial Paste:=8
    > ' Paste:=8 will copy the column width in Excel 2000 and higher
    > ' If you use Excel 97 use the other example
    > Cells(1).PasteSpecial xlPasteValues, , False, False
    > Cells(1).PasteSpecial xlPasteFormats, , False, False
    > Cells(1).Select
    > Application.CutCopyMode = False
    > End With
    >
    > strdate = Format(Now, "dd-mm-yy h-mm-ss")
    > With dest
    > SaveAs "Selection of " & ThisWorkbook.Name _
    > & " " & strdate & ".xls"
    > SendMail "", "This is the Subject line"
    > ChangeFileAccess xlReadOnly
    > Kill .FullName
    > Close False
    > End With
    > Application.ScreenUpdating = True
    > End Sub
    >
    >
    > --
    > parteegolfer
    > ------------------------------------------------------------------------
    > parteegolfer's Profile: http://www.excelforum.com/member.php...o&userid=31951
    > View this thread: http://www.excelforum.com/showthread...hreadid=523999
    >




  3. #3
    Registered User
    Join Date
    02-26-2006
    Posts
    68
    Thanks Ron,

    This worked out well, I was putting the code in the wrong place but I did have the right idea. I was placing the code higher in the application.

    Thanks Again!

+ 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