如何使用VBA将电子邮件作为对象附加到单元格中?

时间:2013-07-31 04:47:14

标签: vba excel-vba excel

我使用下面的代码将文件附加到Excel工作表中,它可以工作,但文件放在其他文件的顶部。如何在每个单元格中单独放置文件?

   For Each elAtt In AttachList
    Set MyAtt = Bug.Attachments.Item(elAtt.ID)
    MyAtt.Load True, ""
    'MsgBox MyAtt.Filename
    ActiveSheet.Cells(i, 2).Value = MyAtt.Filename
    ActiveSheet.Cells(i, 3).Value = MyAtt.Description
    ActiveSheet.Cells(i, 4).Select
    ActiveSheet.OLEObjects.Add Filename:=MyAtt.Filename, Link:=False, DisplayAsIcon:=False, Left:=40, Top:=40, Width:=20, Height:=10
    'ActiveSheet.Cells(i, j).Value = Left(MyAtt.Filename, InStrRev(MyAtt.Filename, "\") - 1)
    'theFileName = MyAtt.Filename
    'thePath = Left(theFileName, InStrRev(theFileName, "\") - 1)
    Set MyAtt = Nothing
i = i + 1
Next

1 个答案:

答案 0 :(得分:0)

答案隐藏在代码的这一行结构中:

ActiveSheet.OLEObjects.Add Filename:=MyAtt.Filename, Link:=False, _
         DisplayAsIcon:=False, Left:=40, Top:=40, Width:=20, Height:=10

引用Add method的{​​{1}}语法:

OLEObjects collection

您需要更改expression.Add(ClassType, FileName, Link, _ DisplayAsIcon, IconFileName, IconIndex, IconLabel, Left, Top, Width, Height) 的{​​{1}}和Left参数。解决方案如下:

Top