首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >shapes.addpicture给出1004错误

shapes.addpicture给出1004错误
EN

Stack Overflow用户
提问于 2013-11-30 22:09:54
回答 2查看 3.4K关注 0票数 2

我有一个相当简单的sub,但它似乎不起作用:

代码语言:javascript
复制
Sub Test()
Dim p as object
strpath = "http://www.someurl.com/sample.jpg" ' some jpg
Set p = ActiveSheet.Shapes.AddPicture(strpath, False, False, 100, 100, 86, 129)
End Sub

当我这样做时,它会给我运行时错误1004,指定值超出范围。但是,如果我将第二个"false“更改为"true",它将正常工作并插入图片。根据this的说法,第二个true/false影响是否将图片与文档一起保存。我不希望这种情况发生。

有人知道为什么会这样吗?

EN

回答 2

Stack Overflow用户

发布于 2013-12-01 00:47:03

这对我很有效:

代码语言:javascript
复制
Sub sof20301212ShapesAddpicture()
  Dim strPath
  Dim p As Object
  strpath = "http://www.google.com/images/srpr/logo11w.png"
  Set p = ActiveSheet.Shapes.AddPicture(strPath, msoCTrue, msoTrue, 100, 100, 86, 129)
End Sub

参考Shapes.AddPicture method

代码语言:javascript
复制
'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对可以是:

代码语言:javascript
复制
 true, true
 true, false
 false, true
票数 3
EN

Stack Overflow用户

发布于 2017-05-26 17:17:31

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20301212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档