我希望能夠使用VBA將圖像作爲Visio中的形狀導入。我試着用下面的插入圖像,但它不工作... myShape.Import(imagePath)
將圖像作爲Visio中的形狀插入 - VBA
然而,myPage.Import(imagePath)
工作正常,並在頁面的中心放置的圖像,但我沒有操縱方式它作爲一個形狀。我試過在網上搜索,但似乎無法找到使用VBA的方法。
我希望能夠使用VBA將圖像作爲Visio中的形狀導入。我試着用下面的插入圖像,但它不工作... myShape.Import(imagePath)
將圖像作爲Visio中的形狀插入 - VBA
然而,myPage.Import(imagePath)
工作正常,並在頁面的中心放置的圖像,但我沒有操縱方式它作爲一個形狀。我試過在網上搜索,但似乎無法找到使用VBA的方法。
上@tim就擴大和這裏@mike評論是一個快速的片段,它包裝進口部分爲功能
Sub TryAddImage()
Dim vPag As Visio.Page
Set vPag = ActivePage
Dim shpImg As Visio.Shape
Set shpImg = AddImageShape(vPag, "C:\MyImage.jpg")
If Not shpImg Is Nothing Then
'Do something to your new shape
shpImg.CellsU("Width").FormulaU = "=Height*0.5"
End If
End Sub
Private Function AddImageShape(ByRef vPag As Visio.Page, fileName As String) As Visio.Shape
Dim shpNew As Visio.Shape
If Not vPag Is Nothing Then
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Insert image shape")
On Error Resume Next:
Set shpNew = vPag.Import(fileName)
If Not shpNew Is Nothing Then
Application.EndUndoScope UndoScopeID1, True
Else
Application.EndUndoScope UndoScopeID1, False
End If
End If
Set AddImageShape = shpNew
End Function
基本上,函數試圖從import method返回的形狀。如果方法通過不存在的路徑或未安裝相應的圖像過濾器創建錯誤,則該函數返回「Nothing」,然後可以在調用代碼中對此進行測試。
感謝您的幫助! – 2013-05-10 17:26:51
'Import()'返回對導入形狀的引用。您可以使用該參考來操縱圖像。 '設置shp =導入(imagePath)' – 2013-05-09 16:43:50
喜蒂姆,雖然沒有導入功能。 – 2013-05-09 17:07:13
爲了澄清,Page.Import返回一個您可以操作的形狀。例如,其中一種操作可以是將新圖像形狀添加到作爲圖像周圍框架的組中。 – 2013-05-09 17:33:42