'はさんでカッコ
function main
dim itemselected, selectedtext, textleft, textright, pos
dim item(10)
dim itemtext(10)
'メニュー項目 配列使用なので返されるのはインデックス値
item(1) = "[ESC] 終了"
item(2) = "-"
item(3) = "[[#]]"
item(4) = "==== # ===="
item(5) = "=== # ==="
item(6) = "== # =="
'メニューに対応する文字列データ
itemtext(1) = ""
itemtext(2) = ""
itemtext(3) = "[[#]]"
itemtext(4) = "==== # ===="
itemtext(5) = "=== # ==="
itemtext(6) = "== # =="
itemselected = PopupMenu(item)
selectedtext = itemtext(itemselected)
if itemselected < 3 then exit function
pos = InStr(selectedtext, "#")
textleft = Left(selectedtext, pos-1)
textright = Mid(selectedtext, pos+1)
ActiveDocument.UndoBlock = True
ActivePane.Selection.Text = textleft & ActiveDocument.Selection.Text & textright
ActiveDocument.UndoBlock = False
end function