[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『どうすれば短くなりますか』(ひで)
マクロ記録で以下のことを記述したら マクロが長くなって処理に時間がかかります。
処理を短くするためにVBAを使った方がいいのはわかりますが、 知識が乏しいです。
やりたいことは、アクティブなセルに @「○ハ」と入力し、「○」は12ポイント、「ハ」は9ポイントにする。 A文字を黒くする Bセルを「折り返して全体を表示」にする。 C黒斜線を入れる Dセルの文字を右揃え、下揃えにする。
です。VBAで記述ならかなり短くなりますか。 よろしくお願いします。
ActiveCell.FormulaR1C1 = "○ハ"
With ActiveCell.Characters(Start:=1, Length:=1).Font .Name = "MS Pゴシック" .FontStyle = "太字" .Size = 12 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .Color = -16776961 .TintAndShade = 0 .ThemeFont = xlThemeFontMinor End With With ActiveCell.Characters(Start:=2, Length:=1).Font .Name = "MS Pゴシック" .FontStyle = "太字" .Size = 9 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .Color = -16776961 .TintAndShade = 0 .ThemeFont = xlThemeFontMinor End With With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With With Selection .HorizontalAlignment = xlRight .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With With Selection .HorizontalAlignment = xlRight .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With With Selection.Font .Name = "MS Pゴシック" .FontStyle = "太字" .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic .TintAndShade = 0 .ThemeFont = xlThemeFontMinor End With Selection.Borders(xlDiagonalDown).LineStyle = xlNone With Selection.Borders(xlDiagonalUp) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlHairline End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlHairline End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With Selection.Borders(xlInsideVertical).LineStyle = xlNone Selection.Borders(xlInsideHorizontal).LineStyle = xlNone End Sub
デフォルトだったり、変更の必要のないところは消す。 例えば、 .Name = "MS Pゴシック" フォントの種類を変える必要が無ければ入らない。 .ColorIndex = 0 フォントの色を変更する必要が無ければ入らない。 罫線の変更が無いのなら入らないなど.....。 (Jaka)
提示されたものもVBAだと思いますが。
上記で得られたものの不要な部分を消去したりすると、希望に近づくと思います。 (ROUGE) '---- With ActiveCell .Value = "○ハ" .Characters(1, 1).Font.Size = 12 .Characters(2, 1).Font.Size = 9 .HorizontalAlignment = xlRight .VerticalAlignment = xlBottom .WrapText = True .Font.ColorIndex = xlAutomatic .Borders.LineStyle = xlNone .BorderAround (xlContinuous) With .Borders(xlDiagonalUp) .LineStyle = xlContinuous .Weight = xlThin End With End With
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.