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

このQ&Aのポイント
  • Excel2003を使用している場合、K55からE55までのセルの値を削除し、透明のダイアローグボックスをコピーしていくマクロを作成したことがあります。しかし、今度は任意のセルから実行したい場合、どのようにマクロを作成すればよいでしょうか。お知恵をお貸しください。
  • Excel2003でK55からE55までのセルの値を削除し、透明のダイアローグボックスをコピーしていくマクロを作成しました。しかし、今度は任意のセルから実行する方法を知りたいです。具体的には、選択したセルの右隣から実行するようにするには、どのようにマクロを書けばよいでしょうか。ご教示ください。
  • Excel2003を使用しています。K55からE55までのセルの値を削除し、透明のダイアローグボックスをコピーしていくマクロを作成しました。しかし、今度は任意のセルからマクロを実行したいです。具体的には、選択したセルの右隣から実行する方法を教えていただけないでしょうか。よろしくお願いいたします。
回答を見る
  • ベストアンサー

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

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

  • ベストアンサー
  • okormazd
  • ベストアンサー率50% (1224/2412)
回答No.3

#2です。 訂正 Range("E55:J55").ClearContents ↓ Selection.Resize(rng.Rows.Count, rng.Columns.Count + 4).ClearContents

sherman
質問者

お礼

ありがとうございます。 上記のマクロでうまく動きました。

その他の回答 (3)

  • xls88
  • ベストアンサー率56% (669/1189)
回答No.4

とりあえず、提示されたコードを編集してみました。 ダミーシートで試してください。 意図通りになっているでしょうか? Selectしないようにしています。 Range("E55")をActivecellに置き換えれば、選択されてアクティブなセルが操作対象になります。 Dim i As Integer Range("E55").Resize(, 6).ClearContents 'セル基準でテキストボックスを描画 With Range("E55") With ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, .left, .Top, .Width, .Height) .Fill.Visible = msoFalse .Line.Visible = msoFalse .Characters.Text = "---" With .Characters(Start:=1, Length:=3).Font .Name = "MS Pゴシック" .FontStyle = "標準" .Size = 11 End With .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter End With End With 'Duplicateで先に描画したテキストボックスの複製を作る 'セル基準で配置 For i = 1 To 4 With ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Duplicate .left = Range("E55").Offset(, i).left .Top = Range("E55").Offset(, i).Top End With Next i 'Copyの引数Destinationを使うとクリップボードを経由せずに貼り付け Range("E55").Offset(1).Copy Destination:=Range("E55").Offset(1).Resize(4, 6) '↓でも可 'Range("E55").Offset(1).Copy Range("E55").Offset(1).Resize(4, 6) 基準セルの指定にInputoboxメソッドを使うと良いかも知れません。 セルをクリックで指定することが出来ます。 直接セル番地を入力して指定することも出来ます。 実は奥が深いInputBox http://www.officetanaka.net/excel/vba/tips/tips37.htm

  • okormazd
  • ベストアンサー率50% (1224/2412)
回答No.2

質問にあいまいなところがあって、コードにも無駄が多いので、何をやりたいか明確ではない。 質問の趣旨の、任意の選択セルから実行(コピー)できるようにはしてあるが、追加の質問には答えません。 Sub test() Dim rng As Range Set rng = ActiveCell Range("E55:J55").ClearContents ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 672#, 729#, _ 81#, 13.5).Select Selection.Characters.Text = "---" With Selection.Font .Name = "MS Pゴシック" .FontStyle = "標準" .Size = 11 End With With Selection.ShapeRange .Fill.Visible = msoFalse .Line.Visible = msoFalse End With Selection.HorizontalAlignment = xlCenter Selection.Copy For i = 0 To 4 rng.Offset(0, i).Select ActiveSheet.Paste Next Range("E56").Copy Range("E56:J59").Select ActiveSheet.Paste Range("K59").Select End Sub

  • akina_line
  • ベストアンサー率34% (1124/3287)
回答No.1

こんにちは。  下記サイトをご参照ください。   http://www.happy2-island.com/excelsmile/smile03/capter00701.shtml   選択しているセルの位置を調べてそこから削除するセルを決めたらいいのではないでしょうか。 では。

関連するQ&A

  • 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

  • エクセル。マクロの記録で出来た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 といった形になるのでしょうが、どうもうまく出来ません。 ご教示いただければ幸いです。

  • マクロの実行ボタンを削除するマクロ

    以下のようなコードを書いたのですが シート内にボタンができてそのボタンを最終的には削除したいです 資料作成のテンプレートとして下記コードを書いたのですが 資料ができた時にボタンがあるままだと見栄えがいまいちなのでマクロ実行ボタンを削除したくなりました。 シート数は30枚くらいあるので1シートずつマクロ実行ボタンを削除するのは正直しんどいです 一度にシートを全部選択してマクロ実行ボタンを削除したいです マクロ実行ボタンの箇所は全シート同じ箇所にあります Sub ボタン() Selection.Borders(xlEdgeBottom).LineStyle = xlNone Selection.Borders(xlEdgeRight).LineStyle = xlNone Selection.Borders(xlInsideVertical).LineStyle = xlNone Selection.Borders(xlInsideHorizontal).LineStyle = xlNone ActiveSheet.Buttons.Add(108, 40, 55, 15).Select Selection.OnAction = "図形挿入等倍" Selection.Characters.Text = "図形挿入" With Selection.Characters(Start:=1, Length:=4).Font .Name = "MS Pゴシック" .FontStyle = "標準" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = 1 End With Range("E4").Select ActiveSheet.Buttons.Add(215, 40, 55, 15).Select Selection.OnAction = "赤枠" Selection.Characters.Text = "赤枠" With Selection.Characters(Start:=1, Length:=2).Font .Name = "MS Pゴシック" .FontStyle = "標準" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = 1 End With Range("G4").Select ActiveSheet.Buttons.Add(323, 40, 55, 15).Select Selection.OnAction = "テキスト入り赤四角" Selection.Characters.Text = "テキスト" With Selection.Characters(Start:=1, Length:=4).Font .Name = "MS Pゴシック" .FontStyle = "標準" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = 1 End With Rows("12:12").Select ActiveWindow.FreezePanes = True End Sub

  • 任意のセルでマクロを実行させたい

    アクティブセルにマクロを実行させたいのですがうまくいきません。 2007のエクセルを使用しています。 (1)命令文で指定しているセル(G9:G11)をJ9:J11やR14:R16等でも使用したい。 (2)また作成したマクロを同シート内オートシェイプに登録したい。 よろしくお願いいたします。 Sub Macro2() ' ' Macro2 Macro ' ' Range("G9:G11").Select Selection.ClearContents With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlTop .Orientation = xlVertical .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With With Selection.Font .Name = "MS P明朝" .FontStyle = "標準" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 16777164 .TintAndShade = 0 .PatternTintAndShade = 0 End With ActiveCell.FormulaR1C1 = "搬入" With ActiveCell.Characters(Start:=1, Length:=2).Font .Name = "MS P明朝" .FontStyle = "標準" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With ActiveCell.Characters(1, 2).PhoneticCharacters = "ハンニュウ" Range("G12").Select End Sub

  • マクロを使って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でも、センタリングさせる方法を教えて下さい どうかよろしくお願いします

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

    オートシェイプを使った簡単な寸法線の入った図をマクロで書きました。 ステップごとだと期待どおりのアウトプットなのですが、ダイレクトにマクロを実行すると途中のステップがとんでしまうようです。 どうしてでしょうか。 教えてください。 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

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

    エクセル(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"はオブジェクトの名前のようですが、名前がわかっていないオブジェクト(但し上記マクロで書いたので場所はわかっている)を選択するにはどうしたらいいでしょうか。

  • エクセルVBAのWith~End With構文

    Win2000エクセル2000です。 下記のMacro11はTEST11のようにWith~End Withでくくれると思うのですがエラーになります。 どこがおかしいのでしょうか? Sub Macro11() ActiveSheet.Shapes.AddShape(msoShapeSun, 450, 150, 120, 120).Select Selection.ShapeRange.Line.Weight = 0.75 Selection.ShapeRange.Line.ForeColor.SchemeColor = 64 Selection.ShapeRange.Fill.ForeColor.SchemeColor = 10 Selection.ShapeRange.Fill.OneColorGradient msoGradientFromCorner, 1, 0.59 Selection.ShapeRange.Adjustments.Item(1) = 0.3016 Selection.ShapeRange.ThreeD.SetThreeDFormat msoThreeD7 Selection.ShapeRange.ThreeD.PresetMaterial = msoMaterialMetal Selection.ShapeRange.ThreeD.Depth = 144# End Sub Sub TEST11() With ActiveSheet.Shapes.AddShape(msoShapeSun, 450, 150, 120, 120) .ShapeRange.Line.Weight = 0.75 .ShapeRange.Line.ForeColor.SchemeColor = 64 .ShapeRange.Fill.ForeColor.SchemeColor = 10 .ShapeRange.Fill.OneColorGradient msoGradientFromCorner, 1, 0.59 .ShapeRange.Adjustments.Item(1) = 0.3016 .ShapeRange.ThreeD.SetThreeDFormat msoThreeD7 .ShapeRange.ThreeD.PresetMaterial = msoMaterialMetal .ShapeRange.ThreeD.Depth = 144# End With End Sub

  • Excelでセル上の画像を別のセルにコピーするには

    いつも楽しく勉強させていただいております。 つぎのような処理をしたいのですが、うまくいきません。 1.セル1の上にある画像をセル2の上にコピーする。 2.コピーした画像をセル2の高さと幅にフィットさせる。 まず、このようなマクロを考えてみました。 Range("A1").CopyPicture Range("C1").Select ActiveSheet.Paste ActiveSheet.Shapes(Selection.Name).LockAspectRatio = msoFalse ActiveSheet.Shapes(Selection.Name).Top = Range("C1").Top ActiveSheet.Shapes(Selection.Name).Left = Range("C1").Left ActiveSheet.Shapes(Selection.Name).Height = Range("C1").Height ActiveSheet.Shapes(Selection.Name).Width = Range("C1").Width これですと元の画像がA1のセルより小さい場合、周囲に余白がある形でコピーされてしまいます。 C1にコピーしたら余白はなしでC1の大きさいっぱいに画像を引き延ばしたい(あるいは縮小したい)のです。 そこで次のように変更してみました。 (上のプログラムと一番上の行のみが違います)。 ActiveSheet.Shapes("図 6").Copy Range("C1").Select ActiveSheet.Paste ActiveSheet.Shapes(Selection.Name).LockAspectRatio = msoFalse ActiveSheet.Shapes(Selection.Name).Top = Range("C1").Top ActiveSheet.Shapes(Selection.Name).Left = Range("C1").Left ActiveSheet.Shapes(Selection.Name).Height = Range("C1").Height ActiveSheet.Shapes(Selection.Name).Width = Range("C1").Width これもうまくいきません。 A1にある元の"図 6"は動かしたくないのに、勝手にB1の位置に移動してしまいます。 というのは、"図 6"という画像をコピーすると、同じ名前で画像ができちゃうんですね。 コピー元とコピー先の両方の画像に対して位置や高さを設定することになるようです。 ということで、 1.セル1の上にある画像をセル2の上にコピーする。 2.コピーした画像をセル2の高さと幅にフィットさせる。 これを実現させるにはどうしたらいいでしょう。

  • Excel マクロでチェックボックスに枠線

    エクセルマクロについて教えて下さい。 Excel2003を使用しています。 1つのシートに、フォームツールボックスからチェックボックスを沢山(300個以上)配置しました。 チェックボックスをクリック(オン)するのと同時にチェックボックスに赤い枠線を付けたいのですが、1つのマクロでチェックボックスのオブジェクト名を取得しながら枠線を付けることは出来ませんでしょうか? 以下のマクロを試してみたのですが、Application.Callerの所でエラーになってしまいました。 Sub checkon() ActiveSheet.Shapes(Application.Caller).Select Selection.ShapeRange.Line.Weight = 3# 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 = 10 i = ActiveCell.Address(False, False, xlA1) Range(i).Select End Sub 特定のチェックボックスを指定した場合は、問題ないのですが・・。 (例)ActiveSheet.Shapes("Check Box 1").Select どなたか詳しい方、宜しくお願い致します。

専門家に質問してみよう