0
在毫秒Word中如何使用VBA添加CommandButton併爲其分配宏(仍然使用VBA)?用分配的宏添加一個命令按鈕
我有代碼來添加命令按鈕。如何在每次運行第一個宏時添加一個宏而不添加私人子?
Sub CompareCase()
Dim testname As String
Dim test1, test2, test3
test1 = ""
test2 = ""
test3 = ""
testname = LCase(InputBox("Enter name of test.")
Call SelectAndProcess
Select Case testname
Case "string1"
ActiveDocument.compare Name:=test1, DetectFormatChanges:=False, CompareTarget:=wdCompareTargetOriginal
Case "string2"
ActiveDocument.compare Name:=test2, DetectFormatChanges:=False, CompareTarget:=wdCompareTargetOriginal
Case "string3"
ActiveDocument.compare Name:=test3, DetectFormatChanges:=False, CompareTarget:=wdCompareTargetOriginal
Case Else
MsgBox "Test not found"
End Select
Call Macro_Add_Button
End Sub
我想在創建時爲CommandButton分配一個宏。
Sub Macro_Add_Button()
Dim oCtl
Dim oCmd
ActiveDocument.Content.InsertParagraphAfter
Set oCtl = ActiveDocument.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1", Range:=ActiveDocument.Paragraphs.Last.Range)
Set oCmd = oCtl.OLEFormat.Object
oCmd.Caption = "Score"
End Sub
非常感謝。這是非常有用的信息! – JMG