我用一個小的子程序通過VBA擅長形狀
ActiveSheet.Pictures.Insert(URL).Select
能正常工作與Excel 2003(Windows)中插入圖片到我的表,但不與Excel 2011(蘋果機)工作了。
所以我修改 (如提出http://www.launchexcel.com/google-maps-excel-demo/)我的子程序, 但子程序在
theShape.Fill.UserPicture URL
停止與錯誤消息
「-2147024894(80070002)Fehler DER了Methode UserPicture DES Objekts FillFormat 「
矩形是綠色的!
Sub Q1()
Dim wks As Worksheet
Dim URL As String
Dim i As Long
Dim lastRow As Long
Dim theShape As Shape
Dim pasteCell As Range
' Used Worksheet
Set wks = Worksheets("Blatt1")
' Delete already existing shapes
For Each theShape In wks.Shapes
theShape.Delete
Next theShape
' Check all existing rows in Column K
lastRow = Cells(Rows.Count, "K").End(xlUp).Row
For i = 2 To lastRow
' the URLs are already computed and stored in column K
URL = wks.Range("K" & i).Value
' try to put the images in column L
Set pasteCell = wks.Range("L" & i)
pasteCell.Select
' Create a Shape for putting the Image into
' ActiveSheet.Pictures.Insert(URL).Select is deprecated and does not work any more!!!
Set theShape = wks.Shapes.AddShape(msoShapeRectangle, pasteCell.Left, pasteCell.Top, 200, 200)
' fill the shape with the image after greening
theShape.Fill.BackColor.RGB = RGB(0, 255, 0)
theShape.Fill.UserPicture URL
Next i
End Sub
任何建議或提示?也許我是盲目的蝙蝠....
你確定你所引用的URL實際上是一個圖片嗎?我使用的是Excel 2010(Windows),但是您的子工作正常(我使用了一個示例Google Maps URL)。我會看看'URL'的值。您可能有畸形的鏈接。 – Zairja 2012-08-07 18:58:48
感謝您的提示。但是URL是好的。我也使用Google API,正如我所提到的,這適用於Excel 2003.我沒有更改我的工作表內容。我用給定的URL測試了UserPicture-method,它不起作用。 目前我認爲這個問題可能取決於我的MS-Office的設置。任何經驗? – TomThumb 2012-08-08 06:10:47
URL和本地文件訪問有所不同: 'theShape.Fill.UserPicture「http://maps.googleapis.com/maps/api/streetview?_&location=51.501554,-0.178082&size=512x512&heading=135&fov=100&pitch=0&sensor = false「 以錯誤結尾 'theShape.Fill.UserPicture」Macintosh HD:庫:用戶圖片:鮮花:花。tif「' 作品!! – TomThumb 2012-08-08 07:22:12