プロが教える店舗&オフィスのセキュリティ対策術

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

A 回答 (2件)

例えばセル「B2」にセットしたければ、以下のようにShapeの位置を設定すれば良いです。


 
With Range("B2")
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, _
  .Left, .Top, .Width, .Height).Select
End With
    • good
    • 0
この回答へのお礼

回答ありがとうございます。

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

お礼日時:2010/10/06 08:26

元のコードは、単なる記録マクロのようですね。



>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
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!