+ Reply to Thread
Results 1 to 2 of 2

Runtime Error 1004, code previously worked fine

Hybrid View

  1. #1
    Registered User
    Join Date
    08-13-2015
    Location
    Wiltshire, England
    MS-Off Ver
    2010
    Posts
    15

    Runtime Error 1004, code previously worked fine

    Hi

    Apologies if this has been asked elsewhere.

    I have the following code:

    Sub SendMorningEmails()
    
        With Application
            .EnableEvents = False
        End With
        
        Dim TempFilePath As String
        
        Set appOutlook = CreateObject("outlook.application")
        
        Set Message = appOutlook.CreateItem(olMailItem)
        
        With Message
            .Subject = "Reservation Volumes"
            .HTMLbody = "<p style=font-family:calibri;font-size:14.5>" & "Dear All" & "<br>" & "<br>"
                
    'This section creates an image as a PNG file to embed in the body of the email, the type of image can be altered by changing this designation, ie, to .jpg in the code below
        
        ThisWorkbook.Activate
        Sheet31.Visible = True
        Sheet31.Activate
        Set Plage = Sheet31.Range("F62:O127")
        Plage.CopyPicture
        
        With ThisWorkbook.Worksheets("Morning Emails").ChartObjects.Add(Plage.Left, Plage.Top, Plage.Width, Plage.Height)
            .Activate
            .Chart.Paste
            .Chart.Export Environ$("temp") & "\" & "MEmailFile" & ".png", "PNG"
        End With
        
        Sheet31.ChartObjects(Sheet31.ChartObjects.Count).Delete
        
        Set Plage = Nothing
        
    'This section attaches the embedded image with a Position at 0 to makes the attachment hidden
        
        TempFilePath = Environ$("temp") & "\"
            .Attachments.Add TempFilePath & "MEmailFile.png", olByValue, 0
            
    'This section adds an html <img src=''> link to this image
    'Using the "<br>" fucntion and the text within the speech marks this section adds the signature to the email
        
        .HTMLbody = .HTMLbody _
            & "<img src='cid:MEmailFile.png'" _
            & "<br>" & "Kind regards" _
            & "<br>" & "<br>" & "<B>Rich Thornton</B>" _
            & "<br>" & "Marketing Executive - Mortgages" _
            & "<br>" & "<br>" & "01793 653009" & "<br>" & "<br>" _
            & "<B><font-family:calibri;font-size:14.5><font color=red>Please treat this e-mail and any accompanying documentation as confidential.</font></B>" & "</p>"
            
            .To = Sheet33.Cells(5, 2)
            .Cc = ""
            .Display
        End With
        
        With Application
            .EnableEvents = True
        End With
            
    End Sub
    Which until today worked fine, however when it runs it brings up a runtime 1004 error at the highlighted line. I've tried all I know but can't get it to work. As mentioned is worked fine until today which is odd I feel!

    Thanks in advance

  2. #2
    Registered User
    Join Date
    08-13-2015
    Location
    Wiltshire, England
    MS-Off Ver
    2010
    Posts
    15

    Re: Runtime Error 1004, code previously worked fine

    In fact the code works fine in another (older) workbook, but doesn't in the new one.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem with VBA code - runtime error 1004
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2015, 02:22 AM
  2. [SOLVED] Runtime error 1004 with my saveas code
    By Anto_BT in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-26-2015, 11:49 AM
  3. [SOLVED] Match & Index code results in Runtime error 1004
    By DJvdW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-27-2013, 03:52 AM
  4. Pivot Table code that has previously worked now returns an error
    By brgr4u in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-22-2013, 02:24 PM
  5. [SOLVED] 'Runtime Error 1004' when trying to Rename Worksheet using vba code
    By Raporter65 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-28-2013, 07:43 PM
  6. [SOLVED] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03:34 PM
  7. Runtime Error Code 1004
    By laks in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-19-2007, 07:08 PM

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