Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel电子邮件文本、图像、文本、图像、文本、签名_Excel_Vba_Outlook_Ms Word - Fatal编程技术网

Excel电子邮件文本、图像、文本、图像、文本、签名

Excel电子邮件文本、图像、文本、图像、文本、签名,excel,vba,outlook,ms-word,Excel,Vba,Outlook,Ms Word,经过几天的努力,我承认失败了。我在Excel中工作,希望自动以特定格式起草电子邮件。我在这里和谷歌上进行了搜索,但在以下格式的电子邮件中找不到任何内容:- 言语 形象 言语 形象 言语 签名 我已经找到了一些文字,图像,图像和签名,我已经用来建立我的 这就是我所做的事情的表现:- 它应该是这样的:- 我在所有我尝试过的东西中都留下了注释掉的部分 Sub EmailGenerate() Dim objOutApp As Object, objOutMail As Object Di

经过几天的努力,我承认失败了。我在Excel中工作,希望自动以特定格式起草电子邮件。我在这里和谷歌上进行了搜索,但在以下格式的电子邮件中找不到任何内容:-

  • 言语
  • 形象
  • 言语
  • 形象
  • 言语
  • 签名
我已经找到了一些文字,图像,图像和签名,我已经用来建立我的

这就是我所做的事情的表现:-

它应该是这样的:-

我在所有我尝试过的东西中都留下了注释掉的部分

 Sub EmailGenerate()

 Dim objOutApp As Object, objOutMail As Object
 Dim strBody As String, strSig As String, strEnd As String, strBody2 As String
 Dim rng As Range, rng2 As Range
 Dim r As Long, r2 As Long
 Dim wdDoc As Word.Document
 Dim Selection As Word.Selection
 Dim Selection2 As Word.Selection
 
 r = shEmail.Cells(Rows.Count, 15).End(xlUp).Row
 Set rng = shEmail.Range("K1:" & Cells(r, 21).Address)

 r2 = shEmail.Cells(Rows.Count, 23).End(xlUp).Row
 Set rng2 = shEmail.Range("W1:" & Cells(r2, 29).Address)

 Set objOutApp = CreateObject("Outlook.Application")
 Set objOutMail = objOutApp.CreateItem(0)
 Set wdDoc = objOutMail.GetInspector.WordEditor
 

 With objOutMail
 'If sent on behalf of another email address
' .SentOnBehalfOfName = ""
 'Setting the email conditions
 .To = shEmail.Cells(1, 2).Value
 .CC = shEmail.Cells(2, 2).Value
 .BCC = ""
 'Checks all email names
 .Recipients.ResolveAll
 .Subject = shEmail.Cells(4, 2).Value
 'This must be visible to get the default signature
 .Display
 'Get the html code from the signature
 strSig = .htmlbody
 'This is what the email body should say
  
' rng.Copy
' wdDoc.Application.Selection.Start = Len(strBody)
' wdDoc.Application.Selection.End = wdDoc.Application.Selection.Start
' wdDoc.Application.Selection.PasteAndFormat (wdChartPicture)
' wdDoc.Content.InsertParagraphAfter
' rng2.Copy
' wdDoc.Application.Selection.Start = Len(strBody) + Len(strBody2)
' wdDoc.Application.Selection.End = wdDoc.Application.Selection.Start
' wdDoc.Application.Selection.PasteAndFormat (wdChartPicture)
  

' rng1.Copy
' wdDoc.Paragraphs(2).Range.PasteSpecial , , , , wdPasteBitmap

  
 rng.Copy
 wdDoc.Content.InsertParagraphBefore
 wdDoc.Paragraphs(2).Range.PasteSpecial , , , , wdPasteBitmap
 wdDoc.Content.InsertParagraphAfter
  
 strBody = "<Body style=font-size:11pt;font-family:Calibri>" & shEmail.Cells(5, 2).Value & "</p>" & _
 "<p>" & "</p>" & _
 "<p>" & shEmail.Cells(6, 2).Value & "</p>" & _
 "<p>" & shEmail.Cells(7, 2).Value & "</p>" & _
 "<p>" & "</p>" & _
 "<p>" & shEmail.Cells(8, 2).Value & "</p>"
    
    
strBody2 = "<Body style=font-size:11pt;font-family:Calibri>" & shEmail.Cells(10, 2).Value & "</p>" & _
 "<p>" & "</p>"
   
 rng2.Copy
 wdDoc.Content.InsertParagraphBefore
 wdDoc.Paragraphs(1).Range.PasteSpecial , , , , wdPasteBitmap
 wdDoc.Content.InsertParagraphAfter
    
 objOutMail.htmlbody = strBody2 & _
 .htmlbody
     
    
' rng2.Copy
' wdDoc.Application.Selection.Start = Len(strBody) + Len(strBody2)
' wdDoc.Application.Selection.End = wdDoc.Application.Selection.Start
' wdDoc.Application.Selection.PasteAndFormat (wdChartPicture)

 'Combines the email with image and the signature
 objOutMail.htmlbody = strBody & _
 .htmlbody
  

 'Automatically sends the email, should pop up briefly.
 '.Send

 End With

 On Error GoTo 0
 Set objOutMail = Nothing
 Set objOutApp = Nothing
 
End Sub
Sub-EmailGenerate()
对象为Dim OBJOUTAP,对象为objOutMail
暗字型为弦,字型为弦,强字型为弦,字型为弦
变暗rng As范围,rng2 As范围
调暗r的长度与r2的长度相同
将wdDoc设置为Word.Document
将所选内容设置为单词。所选内容
将选项2设置为单词。选项
r=shEmail.Cells(Rows.Count,15).End(xlUp).Row
设置rng=shEmail.Range(“K1:”&单元格(r,21).Address)
r2=shEmail.Cells(Rows.Count,23).End(xlUp).Row
设置rng2=shEmail.Range(“W1:”&单元格(r2,29).Address)
设置objoutap=CreateObject(“Outlook.Application”)
设置objOutMail=objoutap.CreateItem(0)
设置wdDoc=objOutMail.GetInspector.WordEditor
用objOutMail
'如果代表其他电子邮件地址发送
'.SentonBehalfName=“”
'设置电子邮件条件
.To=shEmail.Cells(1,2).Value
.CC=shEmail.Cells(2,2).Value
.BCC=“”
'检查所有电子邮件名称
.Recipients.ResolveAll
.Subject=shEmail.Cells(4,2).Value
'这必须可见才能获取默认签名
.展示
'从签名中获取html代码
strSig=.htmlbody
这是电子邮件正文应该说的
“收到
'wdDoc.Application.Selection.Start=Len(strBody)
'wdDoc.Application.Selection.End=wdDoc.Application.Selection.Start
'wdDoc.Application.Selection.PasteAndFormat(wdChartPicture)
'wdDoc.Content.InsertParagraphAfter
'rng2.收到
'wdDoc.Application.Selection.Start=Len(strBody)+Len(strBody2)
'wdDoc.Application.Selection.End=wdDoc.Application.Selection.Start
'wdDoc.Application.Selection.PasteAndFormat(wdChartPicture)
'rng1.收到
'wdDoc.parations(2).Range.PasteSpecial,,wdPasteBitmap
收到
wdDoc.Content.InsertParagraphBefore
wdDoc.段落(2).Range.PasteSpecial,,wdPasteBitmap
wdDoc.Content.InsertParagraphAfter
strBody=”“&shEmail.Cells(5,2).Value&“

”和_ “”和“

”和_ “”&shEmail.Cells(6,2).Value&“

”&_ “”&shEmail.Cells(7,2).Value&“

”&_ “”和“

”和_ “”&shEmail.Cells(8,2).Value&“

” strBody2=“”&shEmail.Cells(10,2).Value&“

”和_ “”和“

” rng2.复制 wdDoc.Content.InsertParagraphBefore wdDoc.段落(1).Range.PasteSpecial,,wdPasteBitmap wdDoc.Content.InsertParagraphAfter objOutMail.htmlbody=strBody2&_ .htmlbody 'rng2.收到 'wdDoc.Application.Selection.Start=Len(strBody)+Len(strBody2) 'wdDoc.Application.Selection.End=wdDoc.Application.Selection.Start 'wdDoc.Application.Selection.PasteAndFormat(wdChartPicture) '将电子邮件与图像和签名结合在一起 objOutMail.htmlbody=strBody&_ .htmlbody '自动发送电子邮件,应短暂弹出。 ’发送 以 错误转到0 设置objOutMail=Nothing 设置OBJOUTAP=无 端接头
rng是较大的表,rng2是较小的表

。单元格(5,2)至(8,2)在rng之前,(10,2)在rng之后和rng2之前,然后(12,2)在rng2之后和签名之前

任何帮助都将不胜感激


谢谢,请尝试下一种方法。很难将
WordEditor
与html混合使用,至少我没有这样做,我不知道如何/是否可以这样做。您所需要的一切(我理解)都可以使用
WordEditor
对象或使用
PropertyAccessor
和链接到图片路径的html来完成。我仅在您的改编代码中使用
WordEditor

Sub EmailGenerate()
 Dim objOutApp As Object, objOutMail As Object
 Dim rng As Range, rng2 As Range, shEmail As Worksheet
 Dim r As Long, r2 As Long
 Dim wdDoc As Word.document, wdRange As Word.Range
 
 Set shEmail = ActiveSheet 'use here your necessary sheet
 
 r = shEmail.cells(Rows.count, 15).End(xlUp).row
 Set rng = shEmail.Range("K1:" & cells(r, 21).Address)

 r2 = shEmail.cells(Rows.count, 23).End(xlUp).row
 Set rng2 = shEmail.Range("W1:" & cells(r2, 29).Address)

 Set objOutApp = CreateObject("Outlook.Application")
 Set objOutMail = objOutApp.CreateItem(0)
 Set wdDoc = objOutMail.GetInspector.WordEditor
  
 With objOutMail
    'If sent on behalf of another email address
    '.SentOnBehalfOfName = ""
    'Setting the email conditions
    .To = shEmail.cells(1, 2).Value
    .cc = shEmail.cells(2, 2).Value
    .BCC = ""
    'Checks all email names
    .Recipients.ResolveAll
    .subject = shEmail.cells(4, 2).Value
    'This must be visible to get the default signature
    .display 'Please, look here if its appearance is what you need.
    
    'Declare the string variables to be used:
    Dim strFrst As String, strSec As String, strThird As String, strF As String
    
    'Give values to the strings (they can take the values from the sheet...)
    strFrst = "Hello All!" & vbCrLf & vbCrLf
    strSec = "Please, receive the picture you requested:" & vbCrLf & vbCrLf
    strThird = "And the second picture is following:" & vbCrLf & vbCrLf
    strF = "The last necessary string is here..." & vbCrLf
    
    'Write the first two text lines:________________
    wdDoc.Paragraphs(1).Range.InsertAfter (strFrst)
    wdDoc.Paragraphs(2).Range.InsertAfter (vbCrLf) 'insert an empty line
    wdDoc.Paragraphs(3).Range.InsertAfter (strSec)
    '_______________________________________________
    
    'Embed the first picture__________________________________________
    rng.Copy
    wdDoc.Paragraphs(5).Range.PasteSpecial , , , , wdPasteBitmap
    '_________________________________________________________________
    
    wdDoc.Paragraphs(5).Range.InsertAfter (vbCrLf) 'empty line after first picture
    
    'insert the third string:_______________________
    wdDoc.Paragraphs(6).Range.InsertAfter (strThird)
    '_______________________________________________
      
    'Embed the second picture___________________________________
    rng2.Copy
    wdDoc.Paragraphs(8).Range.PasteSpecial , , , , wdPasteBitmap
    '___________________________________________________________
    
    'insert the fourth string:__________________
    wdDoc.Paragraphs(8).Range.InsertAfter (strF)
    '___________________________________________
    
    
    'Automatically sends the email, should pop up briefly.
    '.Send
 End With
End Sub

请测试并发送一些反馈。

Steven hi-信息非常清楚,但我不确定确切的问题是什么:你能帮我一点忙吗?谢谢约翰,谢谢你的回复。很抱歉我的问题不是很清楚。我想在我的代码错误的地方得到帮助。或者指导如何更好地将其转换为我需要的格式。我在代码下面添加了一个简短的解释,以显示与代码一致的地方应该是什么。我希望这是有道理的。感谢您一个快速观察-您可能知道,但如果不是
“”&“

不会给您换行符,您可以尝试

我不知道,谢谢。
几个月
完成
-您正在寻找那些超链接吗?如果是这样的话,你是如何构建html的?@Steven Byrne:这只意味着我想向你展示一种(仅)处理
WordEditor
的方法,以便在你需要的地方插入图片或字符串。如果不够清晰,我会修改代码,在末尾插入另一个字符串…@Steven Byrne:你的意思是先有图像,然后是文本?如果是,我的情况不是这样的。。。您是否尝试过代码的原样,或者做了一些(可能是小的)调整?请在
rng上放一个换行符。复制
,然后逐行运行代码(按F8键),看看发生了什么……我不能再呆下去了。。。我应该在几分钟前离开办公室。几小时后我在家时,我们可以继续讨论。@Steven Byrne:请测试更新的代码。我创建了一个签名并开始使用
WordEditor
对象。我想它应该是这样的。。。请在测试后发送一些反馈。@Steven Byrne:很高兴我能帮上忙!在玩
WordEditor
的过程中,我也学到了一些东西。不知为什么,