VBA 从 Excel sub 在 Publisher 中绘制形状
VBA Draw shape in Publisher from Excel sub
我在 Xcel 中有一个子程序,我想将格式化的文本框绘制到现有的发布者文档中。但是,当我尝试绘制形状时,它一直给我一个 类型不匹配 。(当作为子文件写在发布者文档上时,这非常有效,但在 excel子)
Sub UpdateInfo()
'Purpose: Input information from xcel sheet to formatted shapes within publisher doc
Dim filename As String
Dim appPub As New Publisher.Application
Dim NameVal As String
Dim NameShp As Shape
'Open publisher doc
filename = GetFilePath & Replace(ThisWorkbook.Name, ".xlsm", ".pub")
appPub.Open (filename)
NameVal = "Test Name"
'**PROBLEM HAPPENS HERE**
'______________________________________________________________
Set NameShp = appPub.ActiveDocument.Pages(1).Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, _
Left:=316.8, Top:=653.04, Width:=254.88, Height:=16.68)
'______________________________________________________________
NameShp.TextFrame.TextRange.Text = NameVal
NameShp.TextFrame.TextRange.Font.Name = "Monsterrat"
NameShp.TextFrame.TextRange.Font.Size = 11
NameShp.TextFrame.TextRange.Font.Color.RGB = RGB(17, 145, 208)
appPub.ActiveDocument.Close
End Sub
我试过使用整数而不是浮点数作为左上宽和左上宽,但这也没有解决问题。 Shapes.AddTextbox 中的某些内容无法正常工作,我不明白为什么。
ExcelShape
不是发布者Shape
。
Dim NameShp As Shape
等同于
Dim NameShp As Excel.Shape
你需要
Dim NameShp As Publisher.Shape
我在 Xcel 中有一个子程序,我想将格式化的文本框绘制到现有的发布者文档中。但是,当我尝试绘制形状时,它一直给我一个 类型不匹配 。(当作为子文件写在发布者文档上时,这非常有效,但在 excel子)
Sub UpdateInfo()
'Purpose: Input information from xcel sheet to formatted shapes within publisher doc
Dim filename As String
Dim appPub As New Publisher.Application
Dim NameVal As String
Dim NameShp As Shape
'Open publisher doc
filename = GetFilePath & Replace(ThisWorkbook.Name, ".xlsm", ".pub")
appPub.Open (filename)
NameVal = "Test Name"
'**PROBLEM HAPPENS HERE**
'______________________________________________________________
Set NameShp = appPub.ActiveDocument.Pages(1).Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, _
Left:=316.8, Top:=653.04, Width:=254.88, Height:=16.68)
'______________________________________________________________
NameShp.TextFrame.TextRange.Text = NameVal
NameShp.TextFrame.TextRange.Font.Name = "Monsterrat"
NameShp.TextFrame.TextRange.Font.Size = 11
NameShp.TextFrame.TextRange.Font.Color.RGB = RGB(17, 145, 208)
appPub.ActiveDocument.Close
End Sub
我试过使用整数而不是浮点数作为左上宽和左上宽,但这也没有解决问题。 Shapes.AddTextbox 中的某些内容无法正常工作,我不明白为什么。
ExcelShape
不是发布者Shape
。
Dim NameShp As Shape
等同于
Dim NameShp As Excel.Shape
你需要
Dim NameShp As Publisher.Shape