如何使用VBA将文件中的图像插入多张图纸

我有一个工作簿有54张。 “Master”“Total”和“Week1”到“Week52”

我试图从文件中插入一张图片到“Week1”到“Week52”的单元格中。

我已经尝试了很多代码,并能够正确地放置图像和大小

下面的代码放置图像,我能够操纵他们得到正确的位置和正确的大小的图像。

但我不能让他们通过其他工作表(周1到周52)

Set oPic = Application.ActiveSheet.Shapes.AddPicture("C:\Users\Public\Documents\Cranes\MinerPic.wmf", False, True, 1, 1, 1, 1) oPic.ScaleHeight 0.3, True oPic.ScaleWidth 0.3, True oPic.Top = Range("p2").Top oPic.Left = Range("p2").Left .OnAction = "FC4.xlsm!MineSheet" 

要么

  pPath = "C:\Users\Public\Documents\Cranes\MinerPic.wmf" With ActiveSheet.Pictures.Insert(pPath) .Left = Range("p2").Left .Top = Range("p2").Top .ShapeRange.Height = 50 .ShapeRange.Width = 50 .OnAction = "FC4.xlsm!MineSheet" 

在一个阶段,我能够把52张图片放在一起。 我怀疑这与Activesheet命令有关。

我非常新的VBA,并会感谢任何帮助。

提前致谢。 史蒂夫。

这样包装你的代码

 For i = 1 To 52 Set sh = ActiveWorkbook.Worksheets("Week" & i) ' Reference the sh object rather than ActiveSheet Set oPic = sh.Shapes.AddPicture( ... ' or With sh.Pictures.Insert(pPath) ' rest of your code Next