Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

This has me stumped!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
parteegolfer - 19 Mar 2006 20:36 GMT
I have this macro to e-mail a sheet when a toolbar button is selected.
can not seem to protect the sheet that is created from the code I hav
below. Can anyone help with this problem, I am stuck!

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)
ActiveSheet.Protect ("My PASSWORD") ' password protection t
sheet(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 Su
K Dales - 20 Mar 2006 15:59 GMT
It appears to me that perhaps this is the problem:
With dest.Sheets(1)
   ActiveSheet.Protect ("My PASSWORD")

You are protecting the active sheet, not dest.Sheets(1)
To protect dest.Sheets(1) it would be
With dest.Sheets(1)
   .Protect ("My PASSWORD")
Signature

- K Dales

> I have this macro to e-mail a sheet when a toolbar button is selected. I
> can not seem to protect the sheet that is created from the code I have
[quoted text clipped - 41 lines]
> Application.ScreenUpdating = True
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.