[英]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.