Hi, I have a workbook with several sheets- lets call it MyWorkbook (The VBA Project should be locked so no one can view code). What I need is to run a code from MyWorkbook to make a copy of this – call it NewWorkbook. Now in NewWorkbook I need to hide sheets Kong,Bong and Dong……then save it as ‘Workbook name’& Date & time. Then email NewWorkbook. (I don’t want to keep any copy of NewWorkbook)
After that I need to Save MyWorkbook (so basically MyWorkbook keeps getting updated with new info everyday, and there are no hidden sheets)
VBA Codes should be password protected in both workbooks.
I tried to write the email code , this is what I have so far…….
Please advise
Thanks
Sub EmailCode()
Dim MyWorkbook As Workbook
Dim NewWorkbook As Workbook
Dim OLApp As Object
Dim EmailItem As Object
Dim EmailRecip As Object
Dim strDate As String
strDate = Format(Date, "dd-mmm-yy") & "." & Format(Time, "hh-mm-ss")
'First I need to save MyWorkbook, then make a copy of it called NewWorkbook
With NewWorkbook
Sheets("BONG").Visible = xlSheetHidden
Sheets("DONG").Visible = xlSheetHidden
Sheets("KONG").Visible = xlSheetHidden
End With
NewWorkbook.SaveAs "Part of" & MyWorkbook.Name & "" & strDate & ".xls"
NewWorkbook.ChangeFileAccess xlReadOnly
Set OLApp = CreateObject("Outlook.Application")
Set EmailItem = OLApp.CreateItem(0)
Set EmailRecip = EmailItem.Recipients.Add("")
EmailItem.Subject = "Daily CTA Reports"
EmailRecip.Type = 1
Dim oRecipient As Object
Set oRecipient = EmailItem.Recipients.Add("")
oRecipient.Type = 2
Dim Msg As String
Msg = "Hello," & vbCrLf & vbCrLf
Msg = Msg & "Previous day's Reports are attached" & vbCrLf & vbCrLf
Msg = Msg & "Many Thanks,"
EmailItem.Body = Msg
EmailItem.Attachments.Add NewWorkbook.FullName
EmailItem.Display 'Send
Kill NewWorkbook.FullName
Set NewWorkbook = Nothing
Set EmailItem = Nothing
Set OLApp = Nothing
End Sub
Bookmarks