1

I'm very new to Python - I'm having issues copying a range in excel as an image and pasting that image in the body of an Outlook email. Please see my code below:

import win32com.client as win32
from PIL import ImageGrab

xlApp = win32.gencache.EnsureDispatch('Excel.Application')


wb = xlApp.Workbooks.Open('U:\Reporting\Templates\Daily_Update_Template_v3.xlsm')
ws = wb.Worksheets('Summary')
win32c = win32.constants
ws.Range(ws.Cells(1,1),ws.Cells(83,14)).CopyPicture(Format= win32c.xlBitmap)
img = ImageGrab.grabclipboard()

Message = 'Hello World!'

outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'email@blaaaaa.com'
mail.Subject = 'Test'
mail.Body = img


mail.Send()

When I run the script, I receive the error the following error:

TypeError: Objects of type 'DibImageFile' can not be converted to a COM VARIANT (but obtaining the buffer() of this object could)

Can anyone help me understand? Thanks!

SQLseed
  • 13
  • 5
  • Check below link https://stackoverflow.com/questions/57024041/using-pasteexceltable-to-copy-excel-data-to-the-body-of-an-outlook-email-with-py – Hietsh Kumar Jan 24 '20 at 12:56

0 Answers0