2016-04-13 14 views
-2

Aşağıdaki kod bir makroyu çalıştırır ve jpeg'i oluşturur. Etkin bir sayfa için sayfanın adını nasıl değiştirebilirim (ör: "Stratejik"). Bir sayfayı kopyaladığımda, kod, referans adı nedeniyle artık çalışmıyor.Arama oluşturJpg (başvuru formu)

With OutMail 
     .SentOnBehalfOfName = "[email protected]" 
     .Display 
     .Subject = "Strategic Sales" 
     .To = "[email protected]" 
> Call createJpg("Strategic", "A1:F11", "Quota") ' 
+1

Sub heet) .ChartObjects.Count) .Delete Seti Plage = Hiçbir şey sonu, biz bu kod yazılmış o dili olabilir? –

+0

Daha spesifik ol, wich dili kullanıldı, bazı kodlar? – Severiano

+0

http://stackoverflow.com/questions/27042842/excel-2010-paste-range-and-picture-into-outlook –

cevap

0

Bir görünüm posta objectand embed görüntüler oluşturmak için bir kod ilgili

Sub sendMail() 
     Application.Calculation = xlManual 
     With Application 
      .ScreenUpdating = False 
      .EnableEvents = False 
     End With 

     Dim TempFilePath As String 

     'Create a new Microsoft Outlook session 
     Set appOutlook = CreateObject("outlook.application") 
     'create a new message 
     Set Message = appOutlook.CreateItem(olMailItem) 


     With Message 
      .Subject = "My mail auto Object" 

      .HTMLBody = "<span LANG=EN>" _ 
       & "<p class=style2><span LANG=EN><font FACE=Calibri SIZE=3>" _ 
       & "Hello,<br ><br >The weekly dashboard is available " _ 
       & "<br>Find below an overview :<BR>" 

      'first we create the image as a JPG file 
      **Call createJpg("Dashboard", "B8:H9", "DashboardFile")** 
      'we attached the embedded image with a Position at 0 (makes the attachment hidden) 
      TempFilePath = Environ$("temp") & "\" 
      .Attachments.Add TempFilePath & "DashboardFile.jpg", olByValue, 0 

      'Then we add an html <img src=''> link to this image 
      'Note than you can customize width and height - not mandatory 

      .HTMLBody = .HTMLBody & "<br><B>WEEKLY REPPORT:</B><br>" _ 
       & "<img src='cid:DashboardFile.jpg'" & "width='814' height='33'><br>" _ 
       & "<br>Best Regards,<br>Ed</font></span>" 

      .To = "[email protected]; [email protected]" 
      .Cc = "[email protected]" 

      .Display 
      '.Send 
     End With 

     With Application 
      .ScreenUpdating = True 
      .EnableEvents = True 
     End With 
     Application.Calculation = xlCalculationAutomatic 
    End Sub 

You need to create createJpg function which transform a range into a jpg file. 


Sub createJpg(Namesheet As String, nameRange As String, nameFile As String) 
    ThisWorkbook.Activate 
    Worksheets(Namesheet).Activate 
    Set Plage = ThisWorkbook.Worksheets(Namesheet).Range(nameRange) 
    Plage.CopyPicture 
    With ThisWorkbook.Worksheets(Namesheet).ChartObjects.Add(Plage.Left, 

Plage.Top, Plage.Width, Plage.Height) .Activate .Chart.Paste . Chart.Export Environ $ ("geçici") & "\" & nameFile & ".jpg" Çalışma Sayfaları (Namesheet) ile "JPG" Bitiş .ChartObjects (Çalışma Sayfaları (İsimler Hemen bu tanımaz olanlar için