Excelで任意のセルを指定する方法

このQ&Aのポイント
  • Excel2003でセルの上を「---」で覆うマクロを作成しました。任意の作成したいセルを「---」で覆うようにするためにはどのように改造すればよいでしょうか?
  • Excel2003でセルの上を「---」で覆うマクロを作成しましたが、現在はセル「K2」に作成されます。任意のセルを「---」で覆うようにするにはどのように変更すればよいですか?
  • Excel2003でセルの上を「---」で覆うマクロを作成しましたが、指定されたセル「K2」以外のセルを「---」で覆う方法はありますか?
回答を見る
  • ベストアンサー

Excel 任意のセルを指定する方法

Excel 任意のセルを指定する方法 こんにちは Excel2003でセルの上を「---」で覆うマクロを作成しました。(以下参照) でもこれはセル「K2」に作成されます。 任意の作成したいセルを「---」で覆うようにするのには どのように改造すればよいでしょうか? おわかりの方お教えください。 ' 透明なセルを一つ作るマクロ ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 672.75, 13.5, _ 81#, 13.5).Select Selection.Characters.Text = "---" With Selection.Characters(Start:=1, Length:=3).Font .Name = "MS Pゴシック" .FontStyle = "標準" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Selection.HorizontalAlignment = xlCenter Selection.ShapeRange.Fill.Visible = msoFalse 'Selection.ShapeRange.Fill.Solid 'Selection.ShapeRange.Fill.Transparency = 0# Selection.ShapeRange.Line.Weight = 0.75 Selection.ShapeRange.Line.DashStyle = msoLineSolid Selection.ShapeRange.Line.Style = msoLineSingle Selection.ShapeRange.Line.Visible = msoFalse Range("K2").Select End Sub

質問者が選んだベストアンサー

  • ベストアンサー
  • Wendy02
  • ベストアンサー率57% (3570/6232)
回答No.2

元のコードは、単なる記録マクロのようですね。 >Selection.ShapeRange.Fill.Visible = msoFalse > 'Selection.ShapeRange.Fill.Solid これって、 > 透明なセルを一つ作るマクロ ではなく、[透明なほ=塗りつぶしをしないオートシェイプを作る]という意味のようです。 >Excel2003でセルの上を「---」で覆うマクロを作成しました。 『「---」で覆う』というのは、囲うという意味ですか? それとも、「---」で埋め尽くすということでしょうか。 Selection.Characters.Text = "---" って、単にテキストボックスに、文字を入れているだけことですが、意味が良く分かりません。  Selection.ShapeRange.Line.Visible = msoFalse としているのですから、Lineそのものは、見えません。  .ShapeRange.Line.DashStyle = msoLineSolid では、「---」は、点線(ドット)ではないようですね。 マクロよりも、日本語解読のほうが遥かに難しいです。 '//標準モジュール Sub Test1()  Dim obj As Shape  If TypeName(Selection) <> "Range" Then MsgBox "セルの上を範囲を囲ってください。", 48: Exit Sub  With Selection   Set obj = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, .Left, .Top, .Width, .Height)  End With  With obj.DrawingObject   .ShapeRange.Fill.Visible = msoFalse   .ShapeRange.Fill.Transparency = 0#   .ShapeRange.Line.Weight = 1#   .ShapeRange.Line.DashStyle = msoLineSolid 'msoLineDash   .ShapeRange.Line.Style = msoLineSingle   .ShapeRange.Line.Transparency = 0#   .ShapeRange.Line.Visible = msoTrue  End With  obj.DrawingObject.TopLeftCell.Select  Set obj = Nothing End Sub

その他の回答 (1)

  • jcctaira
  • ベストアンサー率58% (119/204)
回答No.1

例えばセル「B2」にセットしたければ、以下のようにShapeの位置を設定すれば良いです。   With Range("B2") ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, _   .Left, .Top, .Width, .Height).Select End With

sherman
質問者

お礼

回答ありがとうございます。 希望のセルに透明なダイアローグボックスを貼り付けたいので ちょっとこの方法では面倒です。

関連するQ&A

  • Excel マクロ 任意のセルから実行したい

    こんにちは、Excel2003を使用しています。 ExcelでK55からE55までのセルの値を削除して(空白にして) それぞれに「---を引いた透明のダイアローグボックス」を コピーしていくマクロを作成したことがあります。 このときは開始するセルがK55と決まっていたのですが 今度は任意のセルから(たとえば選択したセルの右隣とか) 実行したいのですがどのようにマクロを作ればよいでしょうか ご存じの方お教えください。 なお参考に上記のマクロを記載します。 Range("E55:J55").Select Selection.ClearContents Range("H55").Select ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 672#, 729#, _ 81#, 13.5).Select Selection.Characters.Text = "" With Selection.Font .Name = "MS Pゴシック" .FontStyle = "標準" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Selection.ShapeRange.Fill.Visible = msoFalse 'Selection.ShapeRange.Fill.Solid 'Selection.ShapeRange.Fill.Transparency = 0# Selection.ShapeRange.Line.Weight = 0.75 Selection.ShapeRange.Line.DashStyle = msoLineSolid Selection.ShapeRange.Line.Style = msoLineSingle Selection.ShapeRange.Line.Transparency = 0# Selection.ShapeRange.Line.Visible = msoFalse ActiveSheet.Shapes("Text Box 12").Select Selection.Characters.Text = "---" With Selection.Characters(Start:=1, Length:=3).Font .Name = "MS Pゴシック" .FontStyle = "標準" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Selection.HorizontalAlignment = xlCenter Range("K55").Select ActiveSheet.Shapes("Text Box 12").Select Selection.Copy Range("I55").Select ActiveSheet.Paste Range("H55").Select ActiveSheet.Paste Range("G55").Select ActiveSheet.Paste Range("F55").Select ActiveSheet.Paste Range("E55").Select ActiveSheet.Paste Range("E56").Select Selection.Copy Range("F56:J56").Select ActiveSheet.Paste Application.CutCopyMode = False Range("E56:J56").Select Selection.Copy Range("E57:E59").Select ActiveSheet.Paste Application.CutCopyMode = False Range("K59").Select End Sub

  • エクセル。マクロの記録で出来たVBAを書き直したい。

    エクセル2000(OSはWindows2000)でマクロの記録を行いました。 四角形を出してA1セルにリンクさせフォント等の設定をしたものです。 Sub Macro5() ActiveSheet.Shapes.AddShape(msoShapeRectangle, 200#, 100#, 140#, 80#). _ Select ExecuteExcel4Macro "FORMULA(""=R1C1"")" With Selection.Font .Name = "Century Gothic" .FontStyle = "太字" .Size = 72 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Selection.ShapeRange.Fill.Visible = msoFalse Selection.ShapeRange.Fill.Transparency = 0# Selection.ShapeRange.Line.Weight = 0.75 Selection.ShapeRange.Line.DashStyle = msoLineSolid Selection.ShapeRange.Line.Style = msoLineSingle Selection.ShapeRange.Line.Transparency = 0# Selection.ShapeRange.Line.Visible = msoFalse End Sub これを、実際には四角形をセレクトしないで実行させたいのです。 With ActiveSheet.Shapes.AddShape~ End With といった形になるのでしょうが、どうもうまく出来ません。 ご教示いただければ幸いです。

  • エクセルマクロでオブジェクトを選択する方法

    エクセル(2002)を使っています。マクロの記録機能を使って円を描くマクロを作成しました。 Sub Maru(xpos, ypos, hankei) ActiveSheet.Shapes.AddShape(msoShapeOval, xpos, ypos, hankei, hankei).Select Selection.ShapeRange.Fill.Visible = msoFalse Selection.ShapeRange.Fill.Solid Selection.ShapeRange.Fill.Transparency = 0# Selection.ShapeRange.Line.Weight = 0.75 Selection.ShapeRange.Line.DashStyle = msoLineSolid Selection.ShapeRange.Line.Style = msoLineSingle Selection.ShapeRange.Line.Transparency = 0# Selection.ShapeRange.Line.Visible = msoTrue Selection.ShapeRange.Line.ForeColor.SchemeColor = 64 Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255) End Sub 次にこの円を削除したいと思い、同じようにマクロの記録機能を使ったところ、 Sub Macro3() ActiveSheet.Shapes("Oval 64").Select Selection.Delete End Sub となりました。"Oval 64"はオブジェクトの名前のようですが、名前がわかっていないオブジェクト(但し上記マクロで書いたので場所はわかっている)を選択するにはどうしたらいいでしょうか。

  • マクロを使ってexcel2007でテキストボックス内をセンタリングしたい

    以前、excel2000でマクロの児童記録で記録し、それを利用して 下のようなマクロを使っていました (列ボックス1は変数) ActiveSheet.Shapes.AddTextbox(msoTextOrientationVerticalFarEast, 列ボックス1, 205 , 15, 105).Select Selection.Characters.Text = 顧客名 With Selection.Characters.Font .Name = "MS Pゴシック" .FontStyle = "標準" .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = 3 End With With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlTop .Orientation = xlVertical .AutoSize = False .AddIndent = False End With Selection.ShapeRange.Fill.Visible = False Selection.ShapeRange.Fill.Solid Selection.ShapeRange.Fill.Transparency = 1# Selection.ShapeRange.Line.Weight = 0.75 Selection.ShapeRange.Line.DashStyle = msoLineSolid Selection.ShapeRange.Line.Style = msoLineSingle Selection.ShapeRange.Line.Transparency = 0# Selection.ShapeRange.Line.Visible = msoFalse Selection.ShapeRange.TextFrame.MarginLeft = 0 Selection.ShapeRange.TextFrame.MarginRight = 0 Selection.ShapeRange.TextFrame.MarginTop = 0 Selection.ShapeRange.TextFrame.MarginBottom = 0 これで問題なく動作していたのですが excel2007で動作させると テキストボックス内が水平方向にセンタリングされていません。 excel2007でテキストボックスをかく記録をしてもマクロには何も残らず 困っています。 excel2007でも、センタリングさせる方法を教えて下さい どうかよろしくお願いします

  • エクセルのVBAのことで

    以下のVBAを実行するとテキストボックスの"あ"という文字で円を描くことができます。 Sub test1() pai = 3.14159 r = 100 Worksheets("sheet1").Activate For s = 0 To 360 Step 15 rd = s / 180 * pai ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, _ 200 + r * Sin(rd), 50 + r - r * Cos(rd), 20, 20).Select Selection.Characters.Text = "あ" Selection.ShapeRange.Fill.Visible = msoFalse Selection.ShapeRange.Line.Visible = msoFalse Next s End Sub この円の半分の半径の円を元の円とドーナツ型(◎)になるように描くにはどのようなスクリプトにすればいいのでしょうか?

  • Excel2007 VBA テキストボックス設定

    Excel2000で作成したVBAコード(テキストボックスの塗りつぶしなし)をExcel2007で実行すると黒く塗りつぶされます。 <実行コード> ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 場所X, 場   所Y, 幅, 高さ).Select Selection.Characters.Text = タイトル1(場所) With Selection.Font .Name = "MS ゴシック" .FontStyle = "標準" .Size = 10 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Selection.ShapeRange.Fill.Visible = msoFalse Selection.ShapeRange.Fill.Transparency = 0# ・・・ (1) 上記コード(1)の部分がおかしいのでしょうか?2000では上手く動きます。 2000 と 2007 の設定の違いがあるのでしょうか? マクロ登録で確認も出来ず、ネットの調べてもわかりませんでした。お力をおかしください。

  • Excel-VBA コメントの書式設定

    Excel-VBA コメントの書式設定 コメントの書式設定をExcel-VBAで定義したい。 従い「マクロの記録」を実行して下記のソースコードを取得しました。 これを実行すると次の実行エラーが発生しました!? ★正常に動作させるソースコードの事例をいただければ幸いです。 ご指導よろしくお願いいたします。 実行時エラー'438' オブジェクトは、このプロパティまたはメソッドをサポートしていません。 Sub Macro1() ' 処理:マクロの記録 ' 目的:「コメントの挿入」と「コメントの書式設定」をする。 Range("A2").Select Range("A2").AddComment Range("A2").Comment.Visible = False Range("A2").Comment.Text Text:="コメント" & Chr(10) & "今日は良いお天気ですね。" '▽次で実行エラーが起きる!? Selection.ShapeRange.ScaleWidth 1.58, msoFalse, msoScaleFromTopLeft Selection.ShapeRange.ScaleHeight 1.49, msoFalse, msoScaleFromTopLeft Selection.ShapeRange.Fill.Visible = msoTrue Selection.ShapeRange.Fill.Solid Selection.ShapeRange.Fill.ForeColor.SchemeColor = 9 Selection.ShapeRange.Fill.Transparency = 0# Selection.ShapeRange.Line.Weight = 0.75 Selection.ShapeRange.Line.DashStyle = msoLineSolid Selection.ShapeRange.Line.Style = msoLineSingle Selection.ShapeRange.Line.Transparency = 0# Selection.ShapeRange.Line.Visible = msoTrue Selection.ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 0) Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255) Selection.ShapeRange.LockAspectRatio = msoTrue Selection.ShapeRange.Height = 141.75 Selection.ShapeRange.Width = 283.5 Range("A1").Select End Sub

  • 【マクロ】ワードアートの文字の輪郭を消す

    excel 2010です。 ワードアートの文字の輪郭を消すマクロを作りたいのですが、 マクロの記憶で、作られた以下のコードでは、消えません。 どうすれば、消せますか。 よろしくお願いします。 Sub Macro() ActiveSheet.Shapes.AddTextEffect(msoTextEffect1,"ABC","Times New Roman",128,False,False,0,0).Select Selection.ShapeRange.TextFrame2.TextRange.Font.Line.Visible = msoFalse End Sub

  • Office VBAについて

    OFFICE2007のプログラムをググったところ 下記のような表記が見つかりました。 ActiveSheet.Shapes.AddShape _ (msoShapeOval, 400.75, 110.75, 30.25, 10.5).Select Selection.ShapeRange.Fill.Visible = msoFalse Selection.ShapeRange.Fill.Transparency = 0# ここで質問ですが、Selection.ShapeRange.Fill.Transparencyの0#とはなんでしょうか。 またAddShapeの中の数値に#を入れているパターンもありました。 いろいろ探したのですが見つかりませんので教えてください。

  • エクセルで簡単なオートシェイプのマクロをつくりました マクロの実行とステップごとの実行の結果がちがってしまいます

    オートシェイプを使った簡単な寸法線の入った図をマクロで書きました。 ステップごとだと期待どおりのアウトプットなのですが、ダイレクトにマクロを実行すると途中のステップがとんでしまうようです。 どうしてでしょうか。 教えてください。 1 Sub 寸法線1() 2 Dim l1, l2, l3, l4, lb, la1, la2, fig1, fig2, fig3, fig4 As Shape 3 x1 = 200 4 y1 = 500 5 x2 = x1 + 100 6 k = Cells(7, 5).Value / Cells(7, 4).Value 7 y2 = y1 - 100 * k 8 Set l1 = ActiveSheet.Shapes.AddLine(x1, y1, x2 + 20, y1) 9 Set l2 = ActiveSheet.Shapes.AddLine(x1, y1, x1, y2 - 15) 10 Set lb = ActiveSheet.Shapes.AddLine(x1, y1, x2, y2) lb.Line.Weight = 2# 11 Set l3 = ActiveSheet.Shapes.AddLine(x2 + 5, y2, x2 + 20, y2) 12 Set l4 = ActiveSheet.Shapes.AddLine(x2, y2 - 5, x2, y2 - 15) 13 Set la1 = ActiveSheet.Shapes.AddLine(x2 + 12.5, y1 - 2, x2 + 12.5, y2 + 2) 14 la1.Line.BeginArrowheadStyle = msoArrowheadTriangle 15 la1.Line.BeginArrowheadLength = msoArrowheadLengthMedium 16 la1.Line.BeginArrowheadWidth = msoArrowheadWidthMedium 17 la1.Line.EndArrowheadStyle = msoArrowheadTriangle 18 la1.Line.EndArrowheadLength = msoArrowheadLengthMedium 19 la1.Line.EndArrowheadWidth = msoArrowheadWidthMedium 20 Set la2 = ActiveSheet.Shapes.AddLine(x1 + 2, y2 - 10, x2 - 2, y2 - 10) 21 la2.Line.BeginArrowheadStyle = msoArrowheadTriangle 22 la2.Line.BeginArrowheadLength = msoArrowheadLengthMedium 23 la2.Line.BeginArrowheadWidth = msoArrowheadWidthMedium 24 la2.Line.EndArrowheadStyle = msoArrowheadTriangle 25 la2.Line.EndArrowheadLength = msoArrowheadLengthMedium 26 la2.Line.EndArrowheadWidth = msoArrowheadWidthMedium 27 Set fig1 = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, _ x1 - 10, y1 + 5, 17, 17) 28 fig1.Select 29 Selection.Characters.Text = Str(Cells(6, 3)) 30 Selection.Characters.Font.Bold = True 31 Selection.ShapeRange.Line.Visible = msoFalse 32 Set fig2 = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, _ x2 + 5, y2 - 20, 18, 18) 33 fig2.Select 34 Selection.Characters.Text = Str(Cells(7, 3)) 35 Selection.Characters.Font.Bold = True 36 Selection.ShapeRange.Line.Visible = msoFalse 37 Set fig3 = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, _ x1 + (x2 - x1) * 0.5 - 13, y2 - 32, 45, 17) 38 fig3.Select 39 Selection.Characters.Text = Str(Cells(7, 4)) 40 Selection.ShapeRange.Line.Visible = msoFalse 41 Set fig4 = ActiveSheet.Shapes.AddTextbox(msoTextOrientationUpward, _ x2 + 15, y1 - 0.5 * (y1 - y2) - 8, 17, 45) 42 fig4.Select 43 Selection.Characters.Text = Str(Cells(7, 5)) 44 Selection.ShapeRange.Line.Visible = msoFalse 45 MsgBox "pause" 46 Call l1.Select 47 Call l2.Select(False) 48 Call l3.Select(False) 49 Call l4.Select(False) 50 Call lb.Select(False) 51 Call la1.Select(False) 52 Call la2.Select(False) 53 Call fig1.Select(False) 54 Call fig2.Select(False) 55 Call fig3.Select(False) 56 Call fig4.Select(False) 57 MsgBox "hit any" 58 Selection.ShapeRange.Group.Delete 59 End Sub Cells(7, 5)=50 cells(7,4)=100 cells(6,3)=1 cells(7,3)=2 です。 左端に行番号をふってあります。 36から44まで飛んでしまいます。 節点 座標 X Y 1 0 0 2 100 50

専門家に質問してみよう