ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Protecting New File (https://www.excelbanter.com/excel-programming/336660-protecting-new-file.html)

MSL[_2_]

Protecting New File
 
I have a simple sub that creates a file, emails the file, then deletes the
file, is it possible to protect the data in the new file in any way. The file
is created from the original file where a range is selected and copied to the
new file.Is it possible to protect the file so that whoever recieves the
email cannot alter the info inside the attachment.
Many Thanks.

Ron de Bruin

Protecting New File
 
Hi MSL

You can protect your worksheet
This example send the selection in a new workbook and protect the sheet (password ron)

Sub Mail_Selection()
Dim source As Range
Dim dest As Workbook
Dim strdate As String

Set source = Nothing
On Error Resume Next
Set source = Selection.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

If ActiveWindow.SelectedSheets.Count 1 Or _
Selection.Cells.Count = 1 Or _
Selection.Areas.Count 1 Then
MsgBox "An Error occurred :" & vbNewLine & vbNewLine & _
"You have more than one sheet selected." & vbNewLine & _
"You only selected one cell." & vbNewLine & _
"You selected more than one area." & vbNewLine & vbNewLine & _
"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
.Protect "Ron"
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


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


"MSL" wrote in message ...
I have a simple sub that creates a file, emails the file, then deletes the
file, is it possible to protect the data in the new file in any way. The file
is created from the original file where a range is selected and copied to the
new file.Is it possible to protect the file so that whoever recieves the
email cannot alter the info inside the attachment.
Many Thanks.




Jim Rech

Protecting New File
 
You can use Tools, Protection to add sheet and workbook protection to make
it more difficult to make changes to an Excel file. This protection is
pretty easy to defeat however.
--
Jim
"MSL" wrote in message
...
|I have a simple sub that creates a file, emails the file, then deletes the
| file, is it possible to protect the data in the new file in any way. The
file
| is created from the original file where a range is selected and copied to
the
| new file.Is it possible to protect the file so that whoever recieves the
| email cannot alter the info inside the attachment.
| Many Thanks.




All times are GMT +1. The time now is 03:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com