【问题标题】:Call createJpg (reference sheet)调用 createJpg(参考表)
【发布时间】:2016-04-13 14:07:10
【问题描述】:

以下代码运行宏并创建 jpeg。 如何更改活动工作表的工作表名称(例如:“战略”)。当我复制工作表时,由于引用名称,代码不再起作用。

With OutMail
        .SentOnBehalfOfName = "Me@Me.Com"
        .Display
        .Subject = "Strategic Sales"
        .To = "Me@Me.Com"
> Call createJpg("Strategic", "A1:F11", "Quota") '

【问题讨论】:

标签: reference call


【解决方案1】:

这是关于创建 Outlook 邮件对象和嵌入图像的代码

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 = "contact1@email.com; contact2@email.com"
            .Cc = "contact3@email.com"

            .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) 。启用 .Chart.Paste .Chart.Export Environ$("temp") & "\" & nameFile & ".jpg", "JPG" 结束于 Worksheets(Namesheet).ChartObjects(Worksheets(Namesheet).ChartObjects.Count).Delete 设置 Plage = 无 结束子

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多