- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经开始运行带有规则和警报的 Outlook 宏了。
宏在收件箱中搜索来自邮件地址的邮件,当找到它时,会将其移动到子文件夹,然后仅从邮件正文中提取号码,打开 Excel,将号码和邮件日期粘贴到Excel 在下一个空闲行上更新 Excel,保存并关闭它。
最后它将邮件移动到 DONE 目录并将其标记为已读。
在 Excel 中,有一个可创建图表的数据透视表(图 3)。
现在我想将该图表从 Excel 发送给邮件收件人,我发现有很多方法可以从 Excel 邮寄图表,但不能从 Outlook 宏邮寄图表。
这是我到目前为止所拥有的:
Sub MoveItems(Item As Outlook.MailItem)
'****************************************************************************
'* Find mail from sender and move them from the inbox to the rquests folder *
'****************************************************************************
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.Folders("Rquests")
Set myItem = myItems.Find("[SenderEmailAddress] = 'mail@domain.com'")
While TypeName(myItem) <> "Nothing"
If myItem.UnRead = True Then
myItem.Move myDestFolder
Set myItem = myItems.FindNext
End If
Wend
'*********************************************************
'* run the Process that extruct the number from the mail *
'*********************************************************
ProcessRequests
End Sub
---------------------------------------------------------------------------
Sub MoveItems2()
'*******************************************************************
'* Move the processed mail from the rquests to the RQ_Done folder *
'*******************************************************************
Dim myNameSpace As Outlook.NameSpace
Dim mySourceFolder As Outlook.Folder
Dim myDestFolder As Outlook.Folder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = Application.GetNamespace("MAPI")
Set mySourceFolder = myNameSpace.GetDefaultFolder(olFolderInbox).Folders("Rquests")
Set myItems = mySourceFolder.Items
Set myDestFolder = mySourceFolder.Folders("RQ_Done")
Set myItem = myItems.Find("[SenderEmailAddress] = 'mail@domain.com'")
While TypeName(myItem) <> "Nothing"
myItem.UnRead = False
myItem.Move myDestFolder
Set myItem = myItems.FindNext
Wend
End Sub
---------------------------------------------------------------------------
Sub ProcessRequests()
On Error Resume Next
Set myOlApp = Outlook.Application
Set myNameSpace = myOlApp.GetNamespace("mapi")
Dim msgtext As String
Dim TimeStamp As Date
'set the outlook folder to look at
Set myfolder = myNameSpace.GetDefaultFolder(olFolderInbox).Folders("Rquests")
'set excel parameters
Dim xlApp As Object
Dim xlWkb As Object
Dim xlSheet As Object
Dim rCount As Long
Set xlApp = CreateObject("excel.application.12")
xlApp.Visible = True
'Open existing excel
Set xlWkb = xlApp.Workbooks.Open("C:\pathtofile\QTYperday.xlsm")
Set xlSheet = xlWkb.Sheets("Data")
xlApp.Worksheets("Data").Activate
'Find the next empty line of the worksheet
rCount = xlSheet.Range("A" & xlSheet.Rows.Count).End(-4162).Row
rCount = rCount + 1
'Search all mail items in current mail directory
For i = 1 To myfolder.Items.Count
Set myItem = myfolder.Items(i)
sender = myItem.SenderEmailAddress
If sender = "mail@domain.com" Then
msgtext = myItem.Body
TimeStamp = myItem.SentOn
'send the body of the mail message to the Function "onlyDigits" that will extract the numbers from it
Dim myStr As String
myStr = onlyDigits(msgtext)
If myStr = "" Then
myStr = "0"
End If
'get the date from date time
mailDateY = DatePart("yyyy", TimeStamp) ' get Year
MailDateM = DatePart("m", TimeStamp) ' get Month
MailDateD = DatePart("d", TimeStamp) ' get Day
MailDateW = DatePart("w", TimeStamp) ' Get day of the week
MailDate = (mailDateY & "/" & MailDateM & "/" & MailDateD) ' Combine it to be a date again
'set the day of the week
If MailDateW = 1 Then
MailDateW = "Sun"
ElseIf MailDateW = 2 Then
MailDateW = "Mon"
ElseIf MailDateW = 3 Then
MailDateW = "Tue"
ElseIf MailDateW = 4 Then
MailDateW = "Wed"
ElseIf MailDateW = 5 Then
MailDateW = "Thu"
End If
MailDay = MailDateW
'write to excel
xlSheet.Range("A" & rCount).value = myStr
xlSheet.Range("B" & rCount).value = MailDate
xlSheet.Range("C" & rCount).value = MailDateW
Else
End If
Next
xlApp.Worksheets("Sheet2").Activate
'Rerash and Save the excel
xlWkb.RefreshAll
xlWkb.Save
'************************
'mail the chart to list *
'************************
'Here I need the code to get the graph from excel and paste it to the email
'as an excel object or picture, It does not matter
'next is sending the mail with the graph (as attachement?)
Dim objMail As Outlook.MailItem
Set objMail = Application.CreateItem(olMailItem)
With objMail
.To = "me@email.com"
.CC = ""
.BCC = ""
.Subject = "Subject Line"
.Body = "Body of mail"
.Attachments.Add 'What, how?
.Send
End With
xlWkb.Close 1
xlApp.Quit
' Mark processed mail as Read and move it to RQ_done folder
MoveItems2
End Sub
---------------------------------------------------------------------------
Function onlyDigits(s As String) As String
'************************************
'* extruct the number from the mail *
'************************************
Dim retval As String ' This is the return string. '
Dim i As Integer ' Counter for character position. '
' Initialise return string to empty '
retval = ""
' For every character in input string, copy digits to '
' return string. '
For i = 1 To Len(s)
If Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Then
retval = retval + Mid(s, i, 1)
If retval = "" Then
retval = "0"
End If
End If
Next
' Then return the return string. '
onlyDigits = retval
End Function
我有一段在 Excel 上运行的代码,它将图表另存为 gif 文件附加并发送,有没有办法将其隐藏以从 Outlook 工作?
Sub SaveSend_Embedded_Chart()
'Working in 2000-2016
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim OutApp As Object
Dim OutMail As Object
Dim Fname As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'File path/name of the gif file
Fname = Environ$("temp") & "\My_Sales1.gif"
'Save Chart named "Chart 1" as gif file
'If you hold down the CTRL key when you select the chart
'in 2000-2013 you see the name in the Name box(formula bar)
ActiveWorkbook.Worksheets("Sheet2").ChartObjects("Chart 3").Chart.Export _
Filename:=Fname, FilterName:="GIF"
On Error Resume Next
With OutMail
.To = "eeee@eeee.com"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add Fname
.Send 'or use .Display
End With
On Error GoTo 0
'Delete the gif file
Kill Fname
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
最佳答案
用 Excel 对象替换 Outlook 对象,无需在 Outlook VBA 宏中创建 Outlook 应用程序实例:
示例
Option Explicit
Sub SaveSend_Embedded_Chart()
Dim Fname As String
Dim App As Excel.Application
Dim xlBook As Excel.Workbook
Dim FilePath As String
Path = "C:\Temp\"
FileName = "Temp.xlsx"
On Error Resume Next
Set App = GetObject(, "Excel.Application")
If Err <> 0 Then
Application.StatusBar = "Please wait while Excel source is opened ... "
Set App = CreateObject("Excel.Application")
xlStarted = True
End If
On Error GoTo 0
'// Open the workbook to input the data
Set xlBook = App.Workbooks.Open(Path & FileName)
'File path/name of the gif file
Fname = Environ$("temp") & "\My_Sales1.gif"
'Save Chart named "Chart 1" as gif file
'If you hold down the CTRL key when you select the chart
'in 2000-2013 you see the name in the Name box(formula bar)
xlBook.Worksheets("Sheet2").ChartObjects("Chart 3").Chart.Export _
FileName:=Fname, FilterName:="GIF"
With OutMail
.To = "email@pcom"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add Fname
.Send 'or use .Display
End With
'Delete the gif file
Kill Fname
xlBook.Close SaveChanges:=True
If xlStarted Then
App.Quit
End If
Set App = Nothing
Set xlBook = Nothing
End Sub
关于excel - 如何从 Outlook 宏发送 Excel 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43118792/
如何在 Excel 中编写可以在我将打开的任何 Excel 文档上工作(使用快捷方式运行)的宏? 这可能吗? 最佳答案 您需要将宏添加到 Personal.xlsb 以使它们可用于所有 excel 文
我正在研究 problem #74在4clojure.com,我的解决方案如下: (defn FPS [s] (->> (map read-string (re-seq #"[0-9]+"
我还没有完全理解Clojure 箭头宏thread-first -> 和thread-last 宏->> 之间的区别。在阅读 https://clojure.org/guides/threading_
我想将一些调试输出语句插入到大型 C 代码库中。这些调试输出语句将由编译器选项开关控制。 调试输出语句如下所示: #ifdef DEBUG_FLAG Print(someSymbol) #endif
我正在通过宏将代码注入(inject)到 C++ 类中。有没有办法根据访问修饰符的上下文来做到这一点?有点像 #if (we_are_in_public_context) INJECT_PUBLIC_
这应该与 memoize 类似,但有很大不同。虽然 memoize 应该与纯函数一起使用,但它通常对加速 IO 相关函数很有用。 我正在寻找的函数/宏应该表现得像高阶函数。它产生的功能应该: 第一次调
对于下面的代码: let services: [MyServices] = [ MyService(), #if DEBUG DebugService(), #endi
假设我有以下文本文件 name: John Doe description: My name is John Doe and I'm really good at vim! name: John Do
在创建 Excel 宏方面需要帮助。我有一个 Excel 工作表。Excel 工作表不一致。我打算使它统一和结构化。 例如。 A B C
我正在 excel 中设置一个宏,以便在更新单元格时自动发送电子邮件。是否可以在电子邮件正文中包含单元格的内容?例如,如果单元格 G7 已更新,请在电子邮件中包含单元格 B7 的内容?单元格行将是相同
我创建了一个简单的 Excel 工作表。 这是我的宏代码: Sub MyMacro() Sheets("Sheet1").Select A$ = Cells(1, 1) Msg
在 Excel 的 VB 宏中,如何删除所有出现的以某个字符串开头的单词? 例如: 字符串内容为:xxxx $AUD543.43 yyyy 我想搜索以 $AUD 开头的字符串中的任何内容并删除下一个空
我是 Excel 宏的新手.. 谁能告诉我这个宏是做什么的? Sub People_Add_Document() prow = ActiveCell.row num = Cells(p
我对 Excel 中的 VBA 和宏非常陌生。我有一个非常大的 Excel 电子表格,其中 A 列保存日期。我正在尝试删除值小于某个日期的行,这就是我到现在为止的想法。 Sub DELETEDATE(
我在 Excel 2003 中有一个 VBA 对象,当通过流数据获得某些值时,它会触发三个简单的宏。它运行良好。我想打开一个重复的工作表,但具有不同的流数据,并在各自的工作表上触发宏。它现在可以使用,
下面的宏有什么问题?我只想评估一个选项卡中的一个单元格是否大于另一个选项卡中的另一个单元格。然后消息框: Sub Comhouse() If Worksheets("(2.2) TRA works
需要一个简单的 excel 宏的帮助。我在第 1 列 X1 到 X20 中有数据。我想自动将此信息粘贴到 A 列,然后当我更新 X 列中的数字时,我想将此信息粘贴到 B 列,然后再粘贴到 C 列...
我找到了以下代码,效果很好;但是,我必须手动更改月份,以便它转到第二个工作簿的右侧工作表。由于工作表以月为单位,我怎样才能使其自动更改为当月? Sub AlarmSheet() Dim wkb As
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .
我的公司只使用 MS Office 2003 产品,所以我必须坚持下去。由于我的工作性质,我需要使用很多“复制和粘贴”功能。源数据主要来自网站,我将数据粘贴到 Excel 中的单元格中。问题是剪贴板保
我是一名优秀的程序员,十分优秀!