[英]Specifying the location of an inlineshape in MS Word (VBA)
我一直在尝试调整此处显示的方法: 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
只要其他一切正常,只需将shp.left = 250和shp.top = 1200设置为
等等等
就像在VB中放置按钮一样。 有关确切呼叫的更多详细信息,您应该参考以下页面: http : //msdn.microsoft.com/zh-cn/library/office/hh965406%28v=office.14%29.aspx
但是说要居中放置一个按钮,您可以将其设置为(doc.width-shape.width)
但是,文字按钮允许更复杂的样式和设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.