- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经能够运行以下代码将 Excel 范围复制到 Outlook 电子邮件中(使用 Ron de Bruin 提供的代码:
Sub SendEMail(SheetName As String, EmailBody As String, EmailSubject As String, MyAttachment As String)
' You need to use this module with the RangetoHTML subroutine.
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, and Outlook 2010.
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Set rng = Nothing
On Error Resume Next
' Only send the visible cells in the selection.
ActiveSheet.Unprotect
Set rng = ActiveSheet.Range(EmailBody).SpecialCells(xlCellTypeVisible)
' You can also use a range with the following statement.
' Set rng = Sheets("YourSheet").Range("D4:D12").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected. " & _
vbNewLine & "Please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
'.To = "ron@debruin.nl"
'.CC = ""
'.BCC = ""
.subject = "Resumen de " & EmailSubject
.htmlbody = RangetoHTML(rng)
' In place of the following statement, you can use ".Display" to
' display the e-mail message.
.Display
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
ActiveSheet.Protect
End Sub
Function RangetoHTML(rng As Range)
' By Ron de Bruin.
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
'Copy the range and create a new workbook to past the data in
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
'.Cells(1).PasteSpecial Paste:=8
'.Cells(1).PasteSpecial xlPasteValues, , False, False
'.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).PasteSpecial xlPasteAll
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
'Close TempWB
TempWB.Close SaveChanges:=False
'Delete the htm file we used in this function
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
最佳答案
我认为代码有点复杂,使用此代码您只能在邮件中插入所选范围的值...如果要添加列的宽度,可以添加代码:
With TempWB.Sheets(1)
.Cells(1).PasteSpecial xlPasteAll
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
' Code ADDED
i = 1
For Each xx In rng.Columns
TempWB.Sheets(1).Columns(i).ColumnWidth = xx.ColumnWidth
i = i + 1
Next
' Code ADDED
'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set mailApp = CreateObject("Outlook.Application")
Set mail = mailApp.CreateItem(olMailItem)
mail.Display
mail.To = "A@a.com"
mail.Subject = "subject" & Now
Dim Clip As MSForms.DataObject
Set Clip = New MSForms.DataObject
Clip.SetText ("test ... body" & vbNewLine & vbNewLine _
& "this is another line " & vbCrLf _
& "this is another line again " & vbNewLine & " ")
Clip.PutInClipboard
Set wEditor = mailApp.ActiveInspector.wordEditor
wEditor.Application.Selection.Paste
Selection.Copy
wEditor.Application.Selection.Paste
' mail.send
关于excel - 在 Outlook 电子邮件中粘贴 Excel 表格 : it looks back,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25023530/
我尝试实现此正则表达式来检查字符串("username")的长度是否在3到30之间,是否仅包含字母(a-z),数字(0-9)和句点(.)(不连续): use regex::Regex; // 1.3.
我又在与正则表达式作斗争了。我一直在尝试添加使用转义字符来转义自定义标记,例如 至 和 至 .在乔治的帮助下,here , 在尝试转义方法之前,以下表达式会产生所需的结果。 ('This is a
我试图根据Python中的正常语法规则正确地分割句子。 我要拆分的句子是 s = """Mr. Smith bought cheapsite.com for 1.5 million dollars,
我有以下将字符串与模式匹配的正则表达式: (?i)(?
我想使用正则表达式过滤掉不使用“\r\n”作为换行符的文件。例如,如果文件包含单个“\n”或单个“\r”,则将被过滤为不合格文件。 我已经找到了: new Regex(@"(?
我正在尝试编写一个正则表达式替换模式,以便替换散列中的数字,如下所示: regexr link some_dict = { TEST: 123 } 这样就可以捕获和替换 123 个。(? " T
因此,我正在使用此查询查询Logstash,该查询返回堆栈顶部的所有内容: { "query": { "match_all": { } }, "size": 7, "_source": { "incl
我正在为 Android 开发 html/javascript 游戏。这是一款棋盘游戏,具有以下功能。它具有不同颜色的图 block ,用户可以在板上放置一个图 block (以编程方式选择)。如果我
所以我目前正在尝试创建一个函数,它将采用两个 3D 点 A 和 B,并为我提供代表 A 点“观察”B 点所需的旋转的四元数(这样点 A 的局部 Z轴穿过点 B,如果你愿意的话)。 我最初找到了this
比如: 第一个数字是:1。 看着第一个数字你可以说1个1,那么第二个数字就是:11。 看着第二个数字你可以说2个1,即第三个数字是:21。 看着第三个
基本上,要点在主题中。 当我创建两个具有固定高度 (2px) 的相同 div,并将缩放比例更改为 75% 或 125% 时,由于某种原因它们“看起来”不同,有人可以解释一下这里发生了什么吗?我该如何解
我正在使用 chrome://inspect/#devices通过cordova检查我的android-app构建的WebView。它在我的 Mac 上运行模拟器。可以找到该设备,但如果我在 WebV
如何使 Angular 服务代码“看起来同步”? 当我清理 Controller 并将业务逻辑代码放入服务中时,我的问题出现了。到目前为止,一切都很好。现在我想在服务函数中“等待”,直到所有异步调用都
标准的 Delphi 控件(面板、按钮等)都有这种斜角效果(顶部和左侧的白线),这给它们带来了 3D 感觉,但今天这让它们看起来很老式。 有没有办法至少在 Delphi 7 中删除这种“3D 外观”?
我有一个在 Win7 上使用 JFileChooser 的 java 应用程序。奇怪的是,有时(经常)但并非总是如此 - 驱动器名称在“查找范围:”组合框中看起来很奇怪: 有没有人知道是什么原因造成的
正在处理一些2015 AoC学习 clojure 的问题...下面的代码对于第 40 次迭代来说足够快,但在那之后很长时间就陷入了停滞。我与其他一些人的解决方案进行了比较,但我并不清楚为什么这么慢。我
我有一个在 Win7 上使用 JFileChooser 的 java 应用程序。奇怪的是,有时(经常)但并非总是如此 - 驱动器名称在“查找范围:”组合框中看起来很奇怪: 有没有人知道是什么原因造成的
我从 JUnit 开始,尝试找到测试的最佳断言方法。 假设我有一个函数来测试它 不返回值 如果输入无效则抛出异常 例如 void foo (int a) throws Exception { if
为了我的优化,我想在 Rcpp 中获得一个像样的 toupper。我对 C++ 很陌生,据我所知,我已经做到了: #include using namespace Rcpp; void C_toup
我在这里不知所措。我有一个简单的地形生成算法在工作,并且通过扩展 ViewPlatformAWTBehavior 和处理我自己的事件,我有一些简单的键盘导航在工作。一切都很好,我可以跟随地形。万岁!
我是一名优秀的程序员,十分优秀!