Excel2007でテキストボックス内をセンタリングする方法

このQ&Aのポイント
  • Excel2007でテキストボックス内をセンタリングする方法について教えてください。
  • 以前はExcel2000でマクロを使用してテキストボックス内をセンタリングしていましたが、Excel2007ではうまく動作しません。
  • Excel2007でもテキストボックス内をセンタリングする方法を教えてください。
回答を見る
  • ベストアンサー

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

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

  • ベストアンサー
  • OtenkiAme
  • ベストアンサー率77% (69/89)
回答No.1

こんにちは。 こういう時は、ステップ実行(F8)で動作を確認してみましょう。 縦書きテキストボックスを作成している時は、 .HorizontalAlignment = xlCenter が水平位置の指定とは限りませんよ。 > .VerticalAlignment = xlTop .VerticalAlignment = xlCenter

nayamu10
質問者

お礼

すばやい回答ありがとうございました。 VerticalAlignmentを変更したところ うまく動作しました。 助かりました。 2003まではどうさしていたので まさかそこに原因があるとは考えもしませんでした。 勉強しますのでまたよろしくお願いします

関連するQ&A

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

  • 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

  • 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 の設定の違いがあるのでしょうか? マクロ登録で確認も出来ず、ネットの調べてもわかりませんでした。お力をおかしください。

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

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

  • 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でテキストボックスに文字

    Excel2016です。 ワークシート上に配置した、図形の「テキストボックス」に文字を入れるVBAについての質問です。 下記のTEST01では期待通り文字が入りますが、これはテキストボックスをSelectしなければなりません。 TEST02ならSelectせずにOKかと思ったら実行時エラーとなりました。 どのように修正したらよろしいのでしょうか? Sub TEST01()   Sheets(“Sheet1”).Shapes.Range(Array("TextBox 3")).Select   Selection.ShapeRange.TextFrame2.TextRange.Characters.Text = "TEST/TEST/2020"   Selection.ShapeRange.TextFrame2.TextRange.Font.Name = "Meiryo UI"   Selection.ShapeRange.TextFrame2.TextRange.Font.Bold = msoTrue End Sub Sub TEST02()   With Sheets(“Sheet1”).Shapes.Range(Array("TextBox 3"))     .ShapeRange.TextFrame2.TextRange.Characters.Text = "TEST/TEST/2020"     .ShapeRange.TextFrame2.TextRange.Font.Name = "Meiryo UI"     .ShapeRange.TextFrame2.TextRange.Font.Bold = msoTrue   End With End Sub

  • 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 どなたか詳しい方、宜しくお願い致します。

  • テキストボックスの表示

    VBAを使って、テキストボックスに表示される内容を設定しているのですが、 下記のように記述とOKですが、 Shapes.Range(Array("Text Box 1")).Select Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "test" Selectを抜かして、 Shapes.Range(Array("Text Box 1")).ShapeRange(1).TextFrame2.TextRange.Characters.Text = "test" のように記述するとエラーになります。 原因がよくわからないのですが、なぜなのでしょうか?

  • エクセルマクロ

    OS:WINDOWS7 SOFT:EXCELL 2007 PC:VAIO VGN-FW73JGB です。マクロで図形入り文字を入れると、文字の右側が切れます。中央に配置するように設定すれば良いですが、その都度変更する必要があるので、教えて頂きたいです。よろしくお願いします。 If CheckBox5 = True Then Set sp = ActiveSheet.Shapes.AddTextbox(msoTextOrientationVertical, 290, 212.5, 20, 45) With sp .TextFrame.Characters.Text = "延 長" sp.Select Selection.ShapeRange.Fill.Visible = msoFalse With sp With .Line .Weight = xlThin .ForeColor.SchemeColor = 8 End With End With End With End If

  • 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

専門家に質問してみよう