• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:xls:CopyFromRecordset罫線描写)

xls:CopyFromRecordset罫線描写

cj_moverの回答

  • cj_mover
  • ベストアンサー率76% (292/381)
回答No.4

あ、すみません。 #1-3、cjです。#2補足欄へのレス、追記です。 直接の回答、候補1)の場合は、 #2補足欄でご提示の(1)の部分に   adoRs.CursorLocation = 3  '  adUseClient を追加してください。 ( 候補2)の場合は不要です。) 失礼しました。

ARIES10
質問者

お礼

記述してみました。 出来ました。 (2)の方でやりました。 実は例示した内容から少し変更を加えました。 しかしできました。 adoRs.Open strSQL, adoCn 'SQLを実行して対象をRecordSetへ Range("B12:AI1000").ClearContents '前のデータクリア Range("B12:AI1000").Font.ColorIndex = xlAutomatic 'フォント色を初期化 Range("B12:AI1000").Borders.LineStyle = xlLineStyleNone Application.EnableEvents = False 'イベントオフ(ワークシートチェンジが反応しないように) i = 12 'スタート行 Do Until adoRs.EOF 'レコードセットが終了するまで処理を繰り返す Cells(i, 2) = adoRs!ID Cells(i, 3) = adoRs!item_no Cells(i, 4) = adoRs!color_no Cells(i, 5) = adoRs!item_name Cells(i, 6) = adoRs!FREE Cells(i, 7) = adoRs![3m] Cells(i, 8) = adoRs![6m] Cells(i, 9) = adoRs![50_0-1m] Cells(i, 10) = adoRs![56_1-2m] Cells(i, 11) = adoRs![62_2-4m] Cells(i, 12) = adoRs![68_4-6m] Cells(i, 13) = adoRs![74_6-9m] Cells(i, 14) = adoRs![80_12m] Cells(i, 15) = adoRs![86_18m] Cells(i, 16) = adoRs![92_2y] Cells(i, 17) = adoRs![98_3y] Cells(i, 18) = adoRs![10_4y] Cells(i, 19) = adoRs![110_5y] Cells(i, 20) = adoRs![116_6y] Cells(i, 21) = adoRs![122_7y] Cells(i, 21) = adoRs![128_8y] Cells(i, 21) = adoRs![134_9y] Cells(i, 21) = adoRs![140_10y] Cells(i, 21) = adoRs![152_12y] Cells(i, 21) = adoRs![164_14y] i = i + 1 '行をカウントアップする adoRs.MoveNext '次のレコードに移動する Loop With Range("B12") .Resize(.End(xlDown).Row - .Row + 1, .End(xlToRight).Column - .Column + 24).Borders.LineStyle = xlContinuous End With 'adoRs.MoveLast ' Range("B12").Resize(adoRs.RecordCount, adoRs.Fields.Count).Borders.LineStyle = xlContinuous Application.EnableEvents = True 'イベントオン 'Application.EnableEvents = False 'イベントオフ(ワークシートチェンジが反応しないように) ' Range("B12").CopyFromRecordset adoRs 'セルへ出力 ' Range("F10:F26").NumberFormatLocal = "yyyy/m/d h:mm;@" '書式設定 'Application.EnableEvents = True 'イベントオン 縦は一発でうまくいき、横にどこまで罫線を引くセルを増やすか、は実際に数字を変えていって答えを得ました。 今回は+24にしました。 このあたり、もしよかったら記述している内容の読み方を教えて頂けますでしょうか。おまじないに数字の増減をしただけより、もう少しだけ内容を理解したいと思いまして。 数日以内にお返事頂けない場合はそのままベストアンサーとして締め切らせて頂きます。 本当にありがとうございました。

ARIES10
質問者

補足

すみません、一つだけうまくいかないケースがありました。 出力するレコードが1レコードだけのときです。 その場合だけは、エクセル内の一番下の行まで全部 罫線が引かれてしまいました。 原因おわかりになりますでしょうか。

関連するQ&A

  • Excel VBAの罫線描画マクロをOpenOfficeCulcで実行。罫線が描画されない。

    Excel VBAで作成したマクロをOpenOffice.orgのCulcに単純移行して 実行してみたのですが、コードは実行されるのに罫線が描画されない 現象が発生しています。 罫線描画はCulcとExcelで互換が遅れている部分だと聞いていますが、 Culc独自のマクロで作成するしか回避方法はないのでしょうか? マクロは下記のような構成になっています。 REM ***** BASIC ***** Option VBASupport 1 Sub draw_line() With Worksheets("drawline") .Range("B2:E8").Borders(xlEdgeLeft).LineStyle = xlContinuous .Range("B2:E8").Borders(xlEdgeTop).LineStyle = xlContinuous .Range("B2:E8").Borders(xlEdgeBottom).LineStyle = xlContinuous .Range("B2:E8").Borders(xlEdgeRight).LineStyle = xlContinuous .Range("B2:E8").Borders(xlInsideVertical).LineStyle = xlContinuous .Range("B2:E8").Borders(xlInsideHorizontal).LineStyle = xlContinuous End With End Sub

  • .NET上でエクセル上に罫線を引く

    VB.NETを独学で勉強しているものです .NETのプログラミングでEXCELを開いてセルに数値を入力するところまではできるようになったのですが、罫線を引こうとするとうまくいきません。 ws.Range(Karist).Borders.LineStyle = xlContinuous のところの「xlContinuous」の下部に波線が出て、変数が宣言されていないと出るのですが、EXCELの定数はどのように宣言すればよいのでしょうか? よろしくお願いいたします

  • VBA罫線

    VBA罫線 a = 9 With Range(Cells(3, 2), Cells(a, 5)) .Borders(xlEdgeTop).LineStyle = xlContinuous .Borders(xlEdgeBottom).LineStyle = xlContinuous .Borders(xlEdgeRight).LineStyle = xlContinuous .Borders(xlEdgeLeft).LineStyle = xlContinuous .Borders(xlInsideVertical).LineStyle = xlContinuous .Borders(xlInsideHorizontal).LineStyle = xlContinuous End With どこのワークシートかを指定する場合はどうしたらいいのでしょうか?

  • エクセル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

  • エクセル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

  • データーに合わせて罫線を引く

    よろしくお願いします。 セル(H6)を起点にデーターのある部分に罫線を引きたいのですが 計算式(関数)が、入っているセルにも罫線が引かれます。 計算式(関数)は入っているが、データーが入っていない場合は罫線を引かない 方法を教えてください。 現況の記述です。 Sub 罫線() With Range("H6").CurrentRegion.Borders .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic With .Item(xlInsideHorizontal) .LineStyle = xlDash .Weight = xlHairline .ColorIndex = xlAutomatic End With With .Item(xlInsideVertical) .LineStyle = xlDash .Weight = xlHairline .ColorIndex = xlAutomatic End With End With End Sub

  • エクセルでデータがある部分だけ罫線で囲いたいです。

    エクセルでデータがある部分だけ罫線で囲いたいです。 エクセルのファイルを開いて、データのある部分だけを罫線で囲みたいです。 データーは常に列数も行数も違います。 マクロの記録で行ったら、以下のようになりました。 もう少し短い文章ではできないでしょうか? Sub Macro1() ' ' Macro1 Macro ' マクロ記録日 : 2010/9/22 ' Range("A1").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).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

  • 表に罫線を最終列まで引きたい

    windows7 とExcel2007でマクロ作成中の初心者です。 最初に、D2:E34を選んで罫線をひき、列を2列移動して、また罫線を引きます。 これをデータのある最終列まで繰り返したいのですが、うまくいきません。 どうしたらよろしいでしょうか。 Sub 勤怠に罫線() Dim n As Integer For n = 1 To 5 勤怠に罫線 Selection.Offset(0, 2).Select 勤怠に罫線 Next n End Sub 以下はマクロの自動記録でコードを書きました。 Sub 勤怠に罫線() Range("D2:E34").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlMedium End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlMedium End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlMedium End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlMedium End With Selection.Borders(xlInsideVertical).LineStyle = xlNone Selection.Borders(xlInsideHorizontal).LineStyle = xlNone Range("D2:E34").Select End Sub

  • AccessVBAでExcelを起動し、罫線を引きたいのですが、Exc

    AccessVBAでExcelを起動し、罫線を引きたいのですが、ExcelVBAの罫線を引く関数をAccessVBAで記述するとエラーになります。どういう記述をすればよいのでしょうか? (例)   以下の様にすると、例えば「xlNone」は宣言されていない等のエラーになります。   (ちなみに、Excelの起動と値の入力はできています) Range("A4:C6").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With

  • ,最終行からA1の間に罫線を引く方法は?

    お願いします。 罫線を引くマクロを書きました。(下記) 範囲のJ26は最終行です。この表のデータ量は変化します。 最終行がJ26とは限りません。Z5000かもしれません。 その範囲に罫線をひくのですが、マクロ的に最終行を認知してA1 まで罫線を引くマクロをどう記述すればよいのか教えてください。 Sheets("読み込み").Select Range("A1:J26").Select Range("J26").Activate 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 Range("J3").Select End Sub