- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有initially answered问题How to only paste visible cells in an email body
我测试和发布的代码(见下文)不包括发送电子邮件。在OP将其添加到他的问题后,我添加了 .Send
部分,但我获得的行为非常奇怪。如果我在发送之前放置一个断点,并执行 Sub
,则会创建一封包含正确信息的电子邮件(包括粘贴的 Excel Range
)。然后我继续执行并且电子邮件被正确发送。但是,如果我立即运行整个 Sub
(没有断点),则发送的电子邮件正文中不会粘贴 Excel Range
。
这是什么原因,解决办法是什么?
我尝试注释/取消注释最后两行(Set ... = Nothing
),但没有帮助。
相关问题:
Copy range of cells from Excel to body of email in Outlook
Pasting formatted Excel range into Outlook message
<小时/>引用代码(基于 Ron de Bruin 的典型代码,请参阅 this 和 this):
Sub SendEmail()
Dim OutlookApp As Object
'Dim OutlookApp As Outlook.Application
Dim MItem As Object
'Dim MItem As Outlook.MailItem
'Create Outlook object
Set OutlookApp = CreateObject("Outlook.Application")
'Set OutlookApp = New Outlook.Application
Dim Sendrng As Range
Set Sendrng = Worksheets("Test").Range("A1").SpecialCells(xlCellTypeVisible)
Sendrng.Copy
'Create Mail Item
Set MItem = OutlookApp.CreateItem(0)
'Set MItem = OutlookApp.CreateItem(olMailItem)
With MItem
.To = "test@email.com"
.To = "SSEREBRINSKY@TENARIS.COM"
.Subject = "Test"
.CC = ""
.BCC = ""
'.Body = "a"
.Display
End With
SendKeys "^({v})", True
With MItem
.Send
End With
'Set OutlookApp = Nothing
'Set MItem = Nothing
End Sub
最佳答案
But if I run the whole Sub at once, with no breakpoints, the email is sent with no pasted Excel Range in the body. What is the reason for that, and what is the solution?
原因很简单。当您使用断点时,您为 Excel 提供了足够的时间来进行复制粘贴。 SendKeys
因此在与其他应用程序一起使用时非常不可靠。
有很多方法可以解决您的问题。一是给复制粘贴足够的时间。您可以使用 DoEvents
来做到这一点或强制 Wait Time
。例如
SendKeys "^({v})", True
DoEvents
或者
SendKeys "^({v})", True
Wait 2 '<~~ Wait for 2 seconds
并在您的代码中使用此子
Private Sub Wait(ByVal nSec As Long)
nSec = nSec + Timer
While nSec > Timer
DoEvents
Wend
End Sub
顺便说一句,而不是使用 SendKeys
您可以使用RangetoHTML
Ron de Bruin 的函数,如图 HERE
编辑
如果以上不起作用,则意味着 SendKeys
在这种情况下执行得太快,请使用 DoEvents/Wait
就在.Display
之后也是如此。
.Display
DoEvents
或者
.Display
Wait 2
关于vba - Excel VBA : Sent Outlook email does not include pasted Range,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20963032/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 11 个月前关闭。 Improve this
这个问题在这里已经有了答案: JavaScript get clipboard data on paste event (Cross browser) (23 个回答) 关闭 8 年前。 我有一个
我有一个 NSTextView,用户可以将纯文本粘贴到其中。 当用户在粘贴板中有“foo”时,我想粘贴“bar”。换句话说,用户转到网络浏览器,选择“foo”,cmd+c,切换到我的 NSTextVi
我对 do.call 如何工作感到困惑。 dat <- data.frame(v1 = c("a", "a", "b", "b"), v2 = c("a", "b"
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我刚刚熟悉 VBA 和我的代码 For k = 3 To ThisWorkbook.Sheets.Count ThisWorkbook.Sheets(k).Activate ActiveSheet.C
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
这个问题在这里已经有了答案: Intercept paste event in Javascript (4 个答案) 关闭 9 年前。 我需要更改粘贴事件的标准行为。我想将 Paste 事件的执行延
只执行一次粘贴我可以使用: noremap p p:let @"="" 粘贴后清空寄存器,后面的粘贴就失效了。然而,将发生的是更新撤消的空粘贴。因此按 p 3 次将需要 3 撤消调用以撤消初始粘贴。
在一个项目中,我发现一些 css 文件“闻起来”就像其中有复制粘贴的规则。 我想知道您检测文件中复制粘贴内容的策略是什么。 只是出于好奇,我想听听您显示文件相似性的提示和技巧! 最佳答案 试试 Sim
考虑以下示例: plot(c(2,4,6)~c(1,2,3),xlab="x", ylab=expression(paste('flux (g ',CO[2]~m^{-2}~h^{-1},')')))
对我来说是真正的问题,因为我不知道解决它。 我编写的 jQuery 脚本应该获取“粘贴”操作的输入值,并通过 ajax 将其传递给 codeigniter Controller 。 它实际上工作得很好
这是我正在尝试解决的问题 - 我完全不确定它是否可能。我有一个网络应用程序,我需要启用从应用程序到应用程序的数据复制/粘贴,但我遇到了粘贴问题。如果我使用 CTRL + V 快捷方式过去,我可以使用
这个问题已经有答案了: Printing newlines with print() in R (5 个回答) 已关闭 8 年前。 使用paste()函数时如何插入新行或者任何在 R 中连接字符串的函
我正在使用 sfsmisc 包中的 pretty10exp() 来使科学记数法看起来更好。例如: library(sfsmisc) a pretty10exp(a, digits.fuzz=3) #
我在下面的数据框中有两列,每一列都有按照特定顺序的级别: head(x1) soa congruency 1 200 9 2 102 2 3 68
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个 edittext 字段,当我想在上面粘贴某人时,“粘贴”弹出窗口的文本颜色(系统默认“粘贴”弹出窗口,不是自定义的)不是与应用程序的全局文本颜色相同,仍然是黑色,很难阅读: 这是我的整体主题
我想自定义 matplotlib 图像显示,以便我可以键入 control-c,它将图像复制到剪贴板,然后我可以将它复制到 openoffice 电子表格以组织我所有的原始数据和图像结果。有什么办法吗
我有一个函数可以计算一些东西,然后将其分配给一个矩阵。该矩阵的名称来自粘贴语句(基于其他一些当前值)。然后我想将 dimnames 分配给矩阵,但不知道如何理解粘贴的名称。 事情是这样的: funct
我是一名优秀的程序员,十分优秀!