0

我一直在尝试调整此处显示的方法:http: //support.microsoft.com/kb/246299,以便我可以在 word 中创建一个命令按钮,该按钮将保存文档并在单击时自行删除。但是,我一直无法弄清楚如何从第一页左上角的默认位置更改按钮的位置。理想情况下,我希望在文档末尾生成按钮并居中对齐,或者放置在光标位置。

任何建议将不胜感激:)

谢谢你。

到目前为止,我的 VB.NET 项目代码:

Dim shp As Word.InlineShape

shp = wrdDoc.Content.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")

shp.OLEFormat.Object.Caption = "Save To Disk"

shp.Width = "100"

'Add a procedure for the click event of the inlineshape

Dim sCode As String

sCode = "Private Sub " & shp.OLEFormat.Object.Name & "_Click()" & vbCrLf & _

"ActiveDocument.SaveAs(""" & sOutFile & """)" & vbCrLf & _

"On Error GoTo NoSave" & vbCrLf & _

"MsgBox ""Document Saved Successfully""" & vbCrLf & _

"Dim o As Object" & vbCrLf & _

"For Each o In ActiveDocument.InlineShapes" & vbCrLf & _

"If o.OLEFormat.Object.Name = ""CommandButton1"" Then" & vbCrLf & _

"o.Delete" & vbCrLf & _

"End If" & vbCrLf & _

"Next" & vbCrLf & _

"Exit Sub" & vbCrLf & _

"NoSave:" & vbCrLf & _

"MsgBox ""Document Failed To Save""" & vbCrLf & _

"End Sub"

wrdDoc.VBProject.VBComponents("ThisDocument").CodeModule.AddFromString(sCode)

wrdApp.Visible = True
4

1 回答 1

0

只要其他一切正常,只需设置 shp.left = 250 和 shp.top = 1200

等等等等

就像在 VB 中放置按钮一样。有关确切调用的更多详细信息,您应该参考此页面:http: //msdn.microsoft.com/en-us/library/office/hh965406%28v=office.14%29.aspx

但是说要居中一个按钮,您可以将 left 设置为 (doc.width - shape.width)

但是文字按钮允许更复杂的样式和设置。

于 2013-07-08T19:04:58.467 回答