- ベストアンサー
VBAの引数の指定 カッコとイコール
例えば Selection.Borders(xlbottom).LineStyle=xlDash のようなプログラムの場合、 Borderプロパティの引数にはカッコを使い、 LineStyleプロパティの引数にはイコールを使いますけど カッコを使う場合とイコールを使う場合は どうやって区別したらよいのでしょうか?
- watermelon7
- お礼率38% (58/149)
- オフィス系ソフト
- 回答数3
- ありがとう数3
- みんなの回答 (3)
- 専門家の回答
質問者が選んだベストアンサー
こんにちは。 オブジェクトを取得するプロパティの場合()を付けて、その中にindexを指定する。 Workbooks(1) Worksheets("Sheet1") ActiveSheet.Shapes(1) ActiveCell.Offset(1,1) Range("A1").Borders(xlEdgeBottom) など 取得したオブジェクトのプロパティに値を設定したり取得する場合=を使って obj.Value=5 obj.Color=vbRed Range("A1").Borders(xlEdgeBottom).LineStyle=xlDash としたり、 x=obj.Value y=obj.Name z=Range("A1").Borders(xlEdgeBottom).LineStyle とする。 少し乱暴かもしれませんが、コレクションからメンバーを取得するプロパティにはカッコが付き、オブジェクトに値を設定するプロパティの場合イコールが付く。 のような感じで区別すれば良いような気がします。
その他の回答 (2)
- BLUEPIXY
- ベストアンサー率50% (3003/5914)
Borders は、セルの4つの辺(Border)のコレクション(配列のようなもの)です。 Borders(xlbottom) で下辺のBorder(オブジェクト)選んだことになります。 LineStyle は、Border オブジェクトのプロパティで、Border(罫線)のスタイルを決めます。 objBorder.LineStyle = xlDash は、そのスタイルの設定をしていることになります。 カッコを使う場合とは、コレクション(配列)になっているかメソッドになっている場合に使うということでイイと思います。 今選んでいる要素がコレクションなのかメソッドなのか単なるプロパティなのかは、その部分を選んでF1キーを押してヘルプを参照して調べます。
- imogasi
- ベストアンサー率27% (4737/17068)
小生勉強十分でなく、やや生半可ですが、 xlbottomはエクセルシステムで定められた定数(組み込み定数)で、具体的には、「数」(2進数?)が定められていて、Bordersというオブジェクトの種類を指定していると思います。全ての種類は組み込み定数が定められているようで、5百以上(は確実)もあるようです(?)。配列の要素の指定のような感じ。 =xlDashは、(xlDashは同じく組み込み定数の一種ですが)、値をプロパティに与えて、それによって形状や体裁描画等のプログラムが実行され、結果的に種類を決めて(選択して)います。 ーーー Sub test01() Cells(1, 1) = xlDash Cells(2, 1) = xlBottom End Sub を実行すると -4115 -4107 となりました。 参考までに Sub test01() Selection.Borders(-4107).LineStyle = -4115 End Sub でも同じになりました。
関連するQ&A
- エクセルVBAにおける罫線の色指定について
エクセルVBAの初心者です。 使用機種はWindows VistaでExcel2007です。 後に示すコードではどうして("B4:H7")までの下罫線と ("C4:H8")までの左罫線が青色にならず、黒色のまま になるのでしょうか?("B4:H7")、("C4:H8")ともに 罫線の色は青色にしたいと思っています。 原因と対処方法をご存知の方ご教示願います。 画像も添付しておりますので、合わせてご参照ください。 Sub 日程表作成() Set WS1 = Worksheets("sheeT1") With WS1 .Range("B3") = "日" .Range("B3").Select End With Selection.AutoFill Destination:=Range("B3:H3") WS1.Range("B3:H3").Select With Selection.Borders(xlLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 5 End With With Selection.Borders(xlTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 5 End With With Selection.Borders(xlBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 5 End With With Selection.Borders(xlRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 5 End With '下線を二重線に変える Range("B3:H3").Select Selection.Borders(xlBottom).LineStyle = xlDouble WS1.Range("B3:H8").BorderAround Weight:=xlThick, _ ColorIndex:=5, LineStyle:=xlContinuous WS1.Range("B3:H8").RowHeight = 35 '日程表の中に横線を入れる WS1.Range("B4:H7").Select Selection.Borders(xlBottom).LineStyle = xlContinuous WS1.Range("B3:H8").BorderAround Weight:=xlThick, _ ColorIndex:=5, LineStyle:=xlContinuous '日程表の中に縦線を入れる WS1.Range("C4:H8").Select Selection.Borders(xlLeft).LineStyle = xlContinuous WS1.Range("B3:H8").BorderAround Weight:=xlThick, _ ColorIndex:=5, LineStyle:=xlContinuous '曜日のセルを塗りつぶす With WS1 .Range("B3:B8").Interior.ColorIndex = 38 .Range("C3:G8").Interior.ColorIndex = 19 .Range("H3:H8").Interior.ColorIndex = 19 .Range("B4").Activate End With End Sub
- ベストアンサー
- Windows Vista
- エクセルVBAで罫線挿入
マクロの記録で下記のように記録されたものを簡潔にまとめるにはどのように記述したらいいでしょうか? Range("C3:F3").Select With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection .HorizontalAlignment = xlCenterAcrossSelection .VerticalAlignment = xlBottom End With
- ベストアンサー
- オフィス系ソフト
- エクセルVBA 行列の数を指定して罫線を引くマクロ教えてください
下のようにSheet1に罫線を引く「開始セル(左右端)」「行」「列」が書いてあります。 この条件で罫線をSheet2に引くようにしたいのですが、変数の設定の仕方などが分かっていないようで、できません。教えていただけないでしょうか。マクロの記録をとったところ、下のようになりました。よろしくお願いします。 開始セル Sheet2!A1・・・Sheet1のB1セル 行 8・・・Sheet1のB2セル 列 2・・・Sheet1のB3セル Sub borders() Range("A1:B8").Select Selection.borders(xlDiagonalDown).LineStyle = xlNone Selection.borders(xlDiagonalUp).LineStyle = xlNone With Selection.borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With End Sub
- ベストアンサー
- オフィス系ソフト
- エクセルVBA 動作させる度に異なる種類の線を書く
エクセル(2007)VBAを使って、マクロを動作させる度に線の種類を変更させたいです。 (1)実線⇒(2)細い実線⇒(3)細線⇒(4)点線⇒(5)線なし 以前質問させて頂き、下記のようにマクロを記載したのですが、(2)⇒(3)へ 動作しません。。。実線と細い実線の定数が同じく「 1 」な事が問題なのかと 思うのですが、何か上手く実行できる方法はありませんでしょうか。。。 何卒宜しくお願い致します。 -------------------------------------------------- Sub 罫線チェンジ() Select Case ActiveCell.Borders.LineStyle Case 1 Selection.Borders.LineStyle = xlContinuous Selection.Borders.Weight = xlHairline Case 1 Selection.Borders.LineStyle = xlThin Case 2 Selection.Borders.LineStyle = xlDash Case -4115 Selection.Borders.LineStyle = xlDot Case -4118 Selection.Borders.LineStyle = xlNone Case Else Selection.Borders.LineStyle = xlContinuous End Select End Sub --------------------------------------------------
- ベストアンサー
- オフィス系ソフト
- エクセルVBA 作動させる度に罫線の種類を変える
エクセル(2007) VBAで、マクロを作動させる度に選択した範囲の 罫線を変更したく、下記のようなマクロを組みましたが1種類の線しか書けません。。。 どのように修正すればよいか教えて頂きたいです。 何卒宜しくお願い致します。 ----------------------------------- Sub 罫線チェンジ() Select Case ActiveCell.Borders.LineStyle Case xlContinuous Selection.Borders.LineStyle = xlHairline Case xlHairline Selection.Borders.LineStyle = xlDot Case xlDot Selection.Borders.LineStyle = xlDouble Case xlDouble Selection.Borders.LineStyle = xlNone Case Else Selection.Borders.LineStyle = xlContinuous End Select End Sub -----------------------------------
- ベストアンサー
- オフィス系ソフト
- VBAで「一度で全ての罫線をなくす」コードを書くときは
With Selection .Borders(xlDiagonalDown).LineStyle = xlNone .Borders(xlDiagonalUp).LineStyle = xlNone .Borders(xlEdgeLeft).LineStyle = xlNone .Borders(xlEdgeTop).LineStyle = xlNone .Borders(xlEdgeBottom).LineStyle = xlNone .Borders(xlEdgeRight).LineStyle = xlNone .Borders(xlInsideVertical).LineStyle = xlNone .Borders(xlInsideHorizontal).LineStyle = xlNone End With これしかないですか? 「一度で全ての罫線をなくす」 みたいなのがあったら教えてください。よろしくお願いします。
- ベストアンサー
- オフィス系ソフト
- VBAで表作成
こんにちわ VBAを使い表を作っているのですが、入力フォームで日付を入力しコマンドボタンを押すと別ブックになり、予め用意してある表に入力した日付から1ヶ月の日付が貼り付けるというのをやっています。 マクロを記録し試してみたところ構文エラーが出てしまいました。 日付を貼り付けるところまでできたのですが・・・ 表には線がすでに入っています。 入力された最後の日付のところで太線で表を閉めたいのですができますでしょうか。 構文エラーになったソースを貼り付けます。 Range((4,"i"+12):(10,"i"+12)).Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlHairline .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With よろしくお願いします
- 締切済み
- その他(プログラミング・開発)
- VBA 選択範囲の中で、更に一番上の行を指定したい!
タイトルの通りです。 選択範囲に罫線を引くマクロを作成しました。 外に太い枠線、中は点線を引き、選択範囲の一番上の行を灰色の塗りつぶしにしたいのです。 しかし、罫線はうまくいきましたが、一番上の行の指定がうまくできません。 Sub 罫線をひく() ' With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlHairline End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlHairline End With ActiveWindow.SmallScroll Down:=12 ←ここを変えたいのですが、どうすればよいかわかりません。 With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorDark1 .TintAndShade = -0.499984740745262 .PatternTintAndShade = 0 End With End Sub どうすればよいか、もしご存知の方がいらっしゃいましたら、ご指導ください。 よろしくお願いたします。
- 締切済み
- その他(プログラミング・開発)
- Excell2007 のVBAでのこと
罫線を引くとき、マクロの記録をとった時 次のような記述が記録されました。 (VBA・マクロの勉強中です) Range("B6:G21").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlDouble .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThick End With この中の .TintAndShade = 0 はどのような働きをするのでしょうか? (何を指定する命令なのでしょうか?) ちなみにエクセル2003ではこの記述はなかったように思うのですが。 初心者ですので分かり易くお願いいします。 どうかよろしく・・・
- ベストアンサー
- オフィス系ソフト
- Excel VBAで罫線を引くマクロを書きたい
Excel VBAで罫線を引くマクロを書きたいと思っています。 で、文末のコードを書きました。(というかマクロ記録したものほぼそのもの) これだとある程度動くのですが、内側線が無いような範囲を選択した場合にはエラーになってしまいます。 内側の線を引く際にIF文をかまさなければならないように思うのですが、イマイチわかりません。 この点について教えてください。 また、コードが冗長であるようにも思えます。もう少しスマートな書き方があればあわせて教えてください。 よろしくお願いします。 Sub 枠線基本() ' 周囲 With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With ' 内側 With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlHairline .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlHairline .ColorIndex = xlAutomatic End With End Sub
- ベストアンサー
- オフィス系ソフト
お礼
みなさんありがとうございます。おかげで理解できました。ところで、もう一つ質問なのですが、 specialcellsメソッドの引数はカッコでくくらないとダメですけど、 引数をカッコでくくらないとダメなメソッドと 引数をカッコでくくる必要の無いメソッドの区別はどうすればよいのでしょうか? 例えば Range("A1:E5").Specialcells(xlCellTypeBlanks).select というように引数をカッコでくくらないと動かないのです。 ところが ほかのメソッドは、引数をカッコでくくらないでも動きます。