0

我正在使用下面的代码将文件附加到 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
4

1 回答 1

0

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

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

它指的是以下Add method语法OLEObjects collection

expression.Add(ClassType, FileName, Link, _
         DisplayAsIcon, IconFileName, IconIndex, IconLabel, Left, Top, Width, Height)

您需要更改LeftTop参数为.Add method. 解决方案可能如下:

ActiveSheet.OLEObjects.Add Filename:=MyAtt.Filename, Link:=False, _
          DisplayAsIcon:=False, Left:=Cells(i, 4).Left, Top:=Cells(i, 4).Top, _
          Width:=20, Height:=10
于 2013-07-31T06:13:25.103 回答