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

xls:CopyFromRecordset罫線描写

cj_moverの回答

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

#1、2、cjです。#2補足欄へのレスです。 要するに、レコードセットの中身が、どのように開かれて どのように読み込まれているか、その状態によって、 adoRs.RecordCountを正しく取得できるかどうかが決まってくる という話でして、#2で示したのは簡単な例として、 自己完結したサンプルプロシージャですので、 今回ご提示の記述に組み込むのは土台、無理なのです。 でもまぁ、ようやくソースを見ることが出来ましたから、 今回はオンデマンドでお応え出来るかと思います。 とりあえず、今までのことは一旦忘れてもらって、 罫線を引く部分だけ書き足すように > Range("B12").CopyFromRecordset adoRs 'セルへ出力 の部分に続けて以下の2行を書き加えます。 候補1)   adoRs.MoveLast   Range("B12").Resize(adoRs.RecordCount, adoRs.Fields.Count).Borders.LineStyle = xlContinuous レコード数をレコードセットに問うのではなくて、 Excelに吐き出されたサイズを取得するなら、 代りに、以下の3行を書き加えます。 候補2)   With Range("B12")     .Resize(.End(xlDown).Row - .Row + 1, .End(xlToRight).Column - .Column + 1).Borders.LineStyle = xlContinuous   End With 直接の回答は以上です。 >「ユーザー定義型は定義されていません。」と > エラーになります。 ADODBを参照設定していないのでしたら当然の(コンパイル)エラーです。 Excel VBAからADODBを扱うのでしたら、 Microsoft ActiveX Data Objects#.# Library に参照設定した方が、何かと扱い易いです。 1) Dim adoRs As Object の代りに、Object型ではなく、 Dim adoRs As ADODB.Recordset ADODBで既定のオブジェクトとして宣言できる、とか、 2)   Set adoCn = CreateObject("ADODB.Connection") の代りに、CreateObjectは使わずに、 Set adoCn = New ADODB.Connection のように高速且つ明示的にアクセス出来るとか、 3)   adUseClient adOpenDynamic adLockOptimistic みたいな、ADODBで定義された組込み定数が使えるようになるとか、 4)   adoRs. までタイプした時点で入力候補が表示されるようになるとか、 色々と便利で能率的に書けるようになります。 配布の問題から配布時に参照設定を外すことはあるかも知れませんが、 開発の段階では参照設定した方が圧倒的に有利です。 疑問を感じて手が止まることも減るでしょうから、 開発を早める意味でも、不慣れな人程、利点は多いと思います。 逆に参照設定しないでADO書きあげちゃう人の方が凄いですし、少数派、と思います。 http://www.happy2-island.com/access/gogo03/capter00307.shtml リンク先は旧いAccessについて解説していますが、 参照設定の手順(設定手順3以降)や解説は参考になるかと思います。 以上です。

ARIES10
質問者

お礼

ありがとうございました。 レコードセットの開き方、読み方によって 扱い方が違うことをご教示くださり まずその部分で大変助かりました。 「レコードセットするときにはこの関数を使えば セットするレコード数がわかります」 的な一意的な内容かと思っていました。 そして、適切なご回答をいただくためには ソースの開示が重要ということも理解しました。 上記のような一意的だという理解だったため ソース貼付は冗長になるかと誤認識していました。 直接のご回答ありがとうございます。 そしてそれ以降のマナーというか、お作法というか、 のご教示もありがとうございます。 今回ADODBという単語に初めて触れてまだ数日という タイミングなのですが、そこでどういうものなのかを 多角的にご教示いただき、今後の参考にできます。 実はウィルス性腸炎か何かにかかったようで ちょっとダウンしていまして、のちほど直接のご回答の 内容を試してみようと思います。 その後No.4の方にもお礼欄でご連絡させていただきます。 ありがとうございました。

関連する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