简体   繁体   English

从Excel发送Outlook电子邮件,将隐藏工作表中的格式化文本放入电子邮件正文中

[英]Send an Outlook email from Excel putting formatted text from a hidden worksheet into the body of the email

I have very little experience of VBA or macros as will, no doubt, become self-evident. 毫无疑问,我对VBA或宏的经验很少,不言自明。 I have got to the point that I can create the email perfectly if I am in the worksheet that holds all the information. 如果我在包含所有信息的工作表中,我已经完全可以创建电子邮件了。 As soon as I step out of that Worksheet then I start to get issues. 一旦我走出该工作表,我就开始遇到问题。 I have tried changing the ActiveWorkbook.EnvelopeVisible = True line to refer to the pertinent worksheet but am failing. 我已经尝试更改ActiveWorkbook.EnvelopeVisible = True行以引用相关的工作表但是失败了。 I have tinkered for a while and tried a few permutations and am struggling to understand what I need to do. 我已经修改了一段时间并尝试了一些排列,我正在努力理解我需要做什么。

Help (please)! 请帮助)!

Ideally I would like to have the workbook only show the worksheets that the users need to see; 理想情况下,我希望工作簿只显示用户需要查看的工作表; this means hiding & protecting the worksheets that have the formula to identify the correct email address(es), subject (various concatenated componants) and the range of cells (formatted and spaced as set out in the worksheet) for the body (as body html or rtf rather than an attachment). 这意味着隐藏和保护具有公式的工作表,以识别正确的电子邮件地址,主题(各种连接的组件)和主体的单元格范围(格式和工作表中列出的间隔)(作为正文html或rtf而不是附件)。 So on buton click an email is created and sent (with user told this has happened). 所以在按钮上点击一个电子邮件被创建并发送(用户告诉这已经发生)。

We have Office 2010 with Outlook in use. 我们正在使用Office 2010和Outlook。

I have adapted the script from http://support.microsoft.com/kb/816644 to the below: 我已将脚本从http://support.microsoft.com/kb/816644改编为以下内容:

Sub MArefEmail()
' MArefEmail Macro
' Create email to provide the referral for the service


   ' Select the range of cells on the active worksheet.
   Worksheets("Referrals").Range("P93:AB113").Select

   ' Show the envelope on the ActiveWorkbook.
   ActiveWorkbook.EnvelopeVisible = True

   ' Set the optional introduction field thats adds
   ' some header text to the email body. It also sets
   ' the To and Subject lines. Finally the message
   ' is sent.
   With Worksheets("Referrals").MailEnvelope
      .Introduction = "Referral requested by applicant during pre-tenancy interview."
      .Item.To = "service@xxx.org.uk"
      .Item.CC = "first.last@xxx.org.uk"
      .Item.Subject = Range("b43").Text
      '.Item.Send
   End With

MsgBox "Referral email sent to yyy service"

End Sub

All help welcome. 欢迎所有帮助。

Background 背景

I have been building an income/expediture calculator with a benefit's assessment, bill estimators and a number fo flags and notifications built in for a Housing Association aimed to help support low-income families. 我一直在建立一个收入/支出计算器,其中包括福利评估,账单估算器以及为住房协会建造的一些标志和通知,旨在帮助支持低收入家庭。 It also has calculations to identify (if pertinent) any loss of benefits income due to recent Welfare Reform - both local and national benefits - and savings. 它还计算确定(如果相关)由于最近的福利改革(包括地方和国家福利)和储蓄而导致的任何福利收入损失。 The organisation has properties across over 100 local authorities each with their own rules. 该组织拥有100多个地方当局的财产,每个地方都有自己的规则。

It is used by front line staff (some technophobic) with the applicant ususally in front of them. 前线工作人员(有些技术恐惧症)通常会将申请人用于他们面前。

The workbook also identifies people that meet certain criteria to flag the offer of a referral to services that might help (eg Employment & Training support). 该工作簿还确定了符合某些标准的人员,以标记提供可能有用的服务的提议(例如就业和培训支持)。 There are six different services, each of which has a number of providers and restrictions, some location-based. 有六种不同的服务,每种服务都有许多提供者和限制,有些是基于位置的。 The referral currently works by flagging that the applicant has met the criteria (to be likely to benefit from the service) and suggests the applicant is offered the service. 推荐目前的工作方式是标记申请人符合标准(可能从服务中受益)并建议申请人获得服务。 If the applicant says "Yes" then a concatenated hyperlink clicked that prefills the To, Cc & Subject fields depending on the location, service, household make-up and property type. 如果申请人说“是”,则点击连接的超链接,根据位置,服务,家庭构成和财产类型预先填写“收件人”,“抄送”和“主题”字段。 The Subject also includes the timeframe for the referral (as give to the customer). 主题还包括推荐的时间范围(作为给予客户)。

Each subject is bespoke. 每个科目都是定制的。 The bespoke subject is used by the people recieving the referral to identify priorities while in the inbox without having to review the body of the email; 接收推荐人的人使用定制主题来识别收件箱中的优先级,而无需查看电子邮件的正文; the bespoke subject is set up to allow sorting as per the referral agency's requirements (ie each one is different!). 定制主题设置为允许按照推荐机构的要求进行排序(即每个主题都不同!)。

The member of staff then needs to move to another worksheet to copy and paste a range of cells into the body of the email. 然后,工作人员需要移动到另一个工作表,将一系列单元格复制并粘贴到电子邮件正文中。 Each of the six referral types has a different range of cells and then send the email. 六种推荐类型中的每一种都具有不同的单元格范围,然后发送电子邮件。 This process ensures the quality of information required for each referral. 此过程可确保每次推荐所需的信息质量。

Speed is a key driver for improvements to the "tool". 速度是改进“工具”的关键驱动因素。 I am at the point of trying to find waste steps and speed improvements. 我正试图找到浪费步骤和提高速度。 Automating the email could save up to 2 minutes per interview and reduce the chance of errors. 自动化电子邮件每次访问最多可节省2分钟,并减少出错的可能性。

You need to hide certain worksheeets as I understand it. 你理解它需要隐藏某些工件。

the worksheets are part of a collection in the workbook. 工作表是工作簿中集合的一部分。

You can either iterate through them by index: 您可以通过索引迭代它们:

dim iIndx as integer

For iindx=1 to worksheets.count
    if worksheets(iindx).name<>"Referrals" then
        worksheets(iindx).visible=xlSheetHidden
    else
        worksheets(iindx).visible=xlSheetVisible
    end if
next

or by member 或由会员

dim oSheet as worksheet

for each osheet in worksheets
    if osheet.name<>"Referrals" then
        osheet.visible=.Visible=xlSheetHidden
    else
        osheet.visible=.Visible=xlSheetVisible
    end if
next

so you can just hide all the other sheets prior to making the Envelope visible, and unhide them later. 因此,您可以在使信封可见之前隐藏所有其他工作表,并在以后取消隐藏它们。

HTH Philip HTH Philip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM