我在这个微软帮助网站上玩VBA代码,为visio文档添加形状。但是,我无法让代码工作,如网站上所示。 以下是包含以下代码的网站:https://msdn.microsoft.com/en-us/library/cc160744.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
以下是我目前的情况:
Imports Microsoft.Office.Interop
Module Module1
Public Property Application As Object
Sub Main()
Dim names As New List(Of String)()
Application.Documents.Add("")
Dim visioDocs As Visio.Documents
Dim visioStencil As Visio.Document = visioDocs.OpenEx("Basic Shapes.vss", CShort(Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked))
Dim visioPage As Visio.Page = Application.ActivePage
Dim visioRectMaster As Visio.Master = visioStencil.Masters("Rectangle")
Dim visioRectShape As Visio.Shape = visioPage.Drop(visioRectMaster, 4.25, 5.5)
visioRectShape.Text = "Rectangle text."
Dim visioStarMaster As Visio.Master = visioStencil.Masters("Star 7")
Dim visioStarShape As Visio.Shape = visioPage.Drop(visioStarMaster, 2.0, 5.5)
visioStarShape.Text = "Star text."
Dim visioHexagonMaster As Visio.Master = visioStencil.Masters("Hexagon")
Dim visioHexagonShape As Visio.Shape = visioPage.Drop(visioHexagonMaster, 7.0, 5.5)
visioHexagonShape.Text = "Hexagon text."
End Sub
End Module
我得到一个空引用异常,无法在Application.Documents.Add(“”)行的末尾处理。我已经通过谷歌尝试了很多解决方案,但未能摆脱错误。关于如何让它运行的任何想法?