[[20080308235217]] 『テキストボックスの角度指定』(づまん) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『テキストボックスの角度指定』(づまん)
 はじめまして、テキストボックスに文字を入力し、
 テキストボックスの書式設定内のサイズで配置角度を指定したいのですが入力できません。
 やはり縦書き、横書きだけなのでしょうか。
 素人的質問ですみません。よろしくお願いいたします。

 文字を入力したテキストボックスを図として
 貼り付けなおすと角度を付けた文字の表示ができます。

 ・作成したテキストボックスを選択した状態で、Shiftキーを押しながら「編集」---「図のコピー」と
   クリックします。

 ・「図のコピー」ダイアログが表示されますが、そのままOKをクリックします。

 ・次にShiftキーを押しながら「編集」---「図の貼り付け」とクリックします。

 ・貼り付けられた図形を回転させれば、文字が角度を持って表示されます。

 ・外枠は角度のない四角形にしたいなら、別に四角形を作成して、グループ化すれば、可能です。

 ichinose

 VBAで角度付きテキストを簡単に作成するなら、
 新規ブックの標準モジュールに

 '=======================================================================
 Sub main()
    Dim shp As Shape
    Dim shp1 As Shape
    Dim x As Double, y As Double, r As Double
    Dim ll As Double, tt As Double, ww As Double, hh As Double
    Dim pai As Double
    Dim rng As Range
    Dim txt As Variant
    Dim kakudo As Double
    If con_textbox(rng, txt, kakudo) = 0 Then
       pai = WorksheetFunction.Pi()
       Set shp = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, _
                                           rng.Left, rng.Top, 100, 100)
       With shp
          With .TextFrame
             .Characters.Font.Size = 16
             .Characters.Text = txt
             .HorizontalAlignment = xlHAlignCenter
             .VerticalAlignment = xlVAlignCenter
             .AutoSize = True
             End With
          .Line.Visible = msoFalse
          .CopyPicture appearance:=xlScreen, Format:=xlPicture
          Set shp1 = .Parent.Pictures.Paste.ShapeRange.Item(1)
          .Delete
          End With
       With shp1
          .Top = rng.Top
          .Left = rng.Left
          .IncrementRotation kakudo
          x = .Left + .Width / 2
          y = .Top + .Height / 2
          r = Sqr(.Width ^ 2 + .Height ^ 2) / 2
          End With
       If kakudo Mod 180 <> 0 Then
          ll = x - Abs(r * Cos(kakudo / 180 * pai)) - 15
          tt = y - Abs(r * Sin(kakudo / 180 * pai)) - 15
          ww = Abs(2 * r * Cos(kakudo / 180 * pai)) + 30
          hh = Abs(2 * r * Sin(kakudo / 180 * pai)) + 30
          If kakudo Mod 90 = 0 Then
             ll = x - 10
             tt = y - r - 10
             ww = shp1.Height + 10
             hh = shp1.Width + 20
             End If
       Else
          ll = shp1.Left - 3
          tt = shp1.Top - 3
          ww = shp1.Width + 6
          hh = shp1.Height + 6
          End If
       Set shp = ActiveSheet.Rectangles.Add(ll, tt, ww, hh).ShapeRange.Item(1)
       shp.ZOrder msoSendToBack
       ActiveSheet.Shapes.Range(Array(shp1.Name, shp.Name)).Group
       End If
 End Sub
 '=======================================================================
 Function con_textbox(作成位置 As Range, テキスト As Variant, 角度 As Double) As Long
    On Error Resume Next
    Dim wk As Variant
    con_textbox = 1
    Set 作成位置 = Application.InputBox("作成位置をセル範囲で指定して", , , , , , , 8)
    If Err.Number = 0 Then
       Set 作成位置 = 作成位置.Cells(1)
       wk = Application.InputBox("表示テキストは?", , , , , , , 2)
       If TypeName(wk) <> "Boolean" Then
          テキスト = wk
          wk = Application.InputBox("回転角度 0〜360", , , , , , , 1)
          If TypeName(wk) <> "Boolean" Then
             角度 = wk
             con_textbox = 0
             End If
          End If
       End If
    On Error GoTo 0
 End Function

 として、mainを実行してみてください。

 まず、作成位置をセルアドレスの指定で決定します。

 次に表示テキストを入力します。

 最後に角度を入力してください。

 これらの条件が正しく指定されると、角度付きテキスト表示が施された図形を作成します。

 試してみてください

 ichinose

ichinoseさん、分かりやすいご説明ありがとうございます。2例とも正常に表示できました。

コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.