+ Reply to Thread
Results 1 to 3 of 3

Creating new identiccal workbook and emailing

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Creating new identiccal workbook and emailing

    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
    Attached Files Attached Files
    Last edited by Pasha81; 11-13-2009 at 01:09 PM.

  2. #2
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: Creating new identiccal workbook and emailing

    Hi,

    All the solutions you can dream of are available ... thanks to Ron ...
    http://www.rondebruin.nl/sendmail.htm

    HTH

  3. #3
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Re: Creating new identiccal workbook and emailing

    thanks Jean
    I found one that I could adjust to make this work

+ 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