首页 > 解决方案 > 我希望将存储在剪贴板中的图像放置到 excel 电子表格上的特定位置

问题描述

我使用 Microsoft 项目作为图像的来源,并希望粘贴到 Excel 工作簿中指定工作表上的特定位置。

Sub CreateImageAndPaste()

Dim EStart As String, LFin As String
EStart = ActiveProject.StatusDate - 30
LFin = Tsk.Finish + 30

'Create View, filter and table in MS Project and apply           

Application.PaneClose                 
MSProject.CalculateAll              
Application.EditCopyPicture Object:=False, ForPrinter:=0, SelectedRows:=0, FromDate:=EarliestStart, ToDate:=LFin, ScaleOption:=pjCopyPictureShowOptions, MaxImageHeight:=-1#, MaxImageWidth:=-1#, MeasurementUnits:=2

With xlsheet
    .Activate
    .Cells(1, 1) = t
    DoEvents
    .Paste
    DoEvents
End With

此片段在复制/粘贴所需图像时非常有效。但是,图像会粘贴到活动工作表的单元格 A1 中。我希望左上角位于单元格 A3 中。如何才能做到这一点?我已经研究了网络,但找不到使用 EditCopy 的图像的示例,请提前致谢。

标签: excelvbams-project

解决方案


请以这种方式尝试:

 With xlsheet
    .Activate
    .Cells(1, 1) = t
    .Paste
    Application.Selection.ShapeRange.item(1).top = .Range("A3").top
    Application.Selection.ShapeRange.item(1).left = .Range("A3").left
 End With

推荐阅读