画像に枠線を施すマクロの書き換え(Word)
画像に枠線を施すマクロの書き換え
前回
枠線を消すマクロで、[InlineShape].Line
プロパティ(=LineFormat
オブジェクト)を用いたので、枠線を施す方も[InlineShape].Line
プロパティを用いる方法に書き換える。
このときのリスト1を書き換えるということ。
書き換えたコード
リスト1
Public Sub SetBordersForFigureMain() Call setBordersForFigure End Sub Private Sub setBordersForFigure( _ Optional ByVal LineStyle As MsoLineStyle = msoLineSingle, _ Optional ByVal LineWeight As Single = 1#) Dim ilShp As InlineShape If Selection.Type = wdSelectionInlineShape Then If Selection.InlineShapes.Count = 0 Then Exit Sub Set ilShp = Selection.InlineShapes(1) Else Exit Sub End If Dim tgtLnFormat As LineFormat '……(1)' Set tgtLnFormat = ilShp.Line With tgtLnFormat '……(2)' .Visible = msoTrue .Style = LineStyle .Weight = LineWeight End With End Sub
(1)からの7行
Dim tgtLnFormat As LineFormat Set tgtLnFormat = ilShp.Line With tgtLnFormat '……(2)' .Visible = msoTrue .Style = LineStyle .Weight = LineWeight End With
は、別に
With ilShp.Line '……(2)' .Visible = msoTrue .Style = LineStyle .Weight = LineWeight End With
と書いてもかまわない。
しかしながら、「LineFormat
オブジェクトを操作しておるのだ!」という感じを出すために、あえてこうしている。大阪府の吉村知事が、〝やってる感〟を出すために「いつ仕事してんのかわからんぐらいテレビに出まくって」いるのと同じである。
(2)の
With ilShp.Line .Visible = msoTrue .Style = LineStyle .Weight = LineWeight End With
では、取得したLineFormat
オブジェクトのうち、Visible
、Style
、Weight
の三つのプロパティのみ設定。
これらは、それぞれ
こいつらに対応している(と思う。)。
使ってみる
バッチリ。
おわりに
これで、枠線を施すマクロと枠線を削除するマクロが、きっちり対応しました。