2017-10-24 3 views
0

私はしばしばExcelでプロセスマップを作成しなければならず、余分な時間を削減しようとしています。各シェイプを作成し、そのシェイプにテキストを入力または貼り付けるのではなく、多くの場合100 +ステップを使用します。列Dのテキストを含む図形を作成するコードを記述しようとしており、列Aのセルにテキストがなくなるまでこれを続けます。図形を作成するためのコードを作成できましたが、別々のブロックにテキストが正しく配置されているようです。 プロセスマッピングのExcel VBAコード

Sub addshapewithtext() 
Dim BlankFound As Boolean 
Dim x As Long 
Dim w As Worksheet 
Dim s As Shape 
Dim t As Variant 
Do While BlankFound = False 
x = x + 1 
Set t = Cells(x, "d") 
Set w = ActiveSheet 
Set s = w.Shapes.addshape(msoShapeFlowchartProcess, 200 + x * 200, 100, 100, 100) 
'format shape 
s.Fill.ForeColor.RGB = RGB(300, 300, 300) 
s.Line.ForeColor.RGB = RGB(0, 0, 0) 
s.Line.Weight = 3 
'transparency 
s.Fill.Transparency = 0 
'add text from list 
s.OLEFormat.Object.Formula = t 
If Cells(x, "A").Value = "" Then 
BlankFound = True 
End If 
Loop 
End Sub 

は、あなたがあなたの形でのテキストとしてのフォントサイズや色を追加したい場合があり s.OLEFormat.Object.Text = t

にあなたの助け

+0

あなたが図形にテキストを追加するマクロを記録する場合は、取得します構文 – SJR

答えて

0

変更s.OLEFormat.Object.Formula = tをありがとう:次のコードは、私がこれまで持っています

私は先に行って、TWEAを追加するために改訂も

少し手を加えてテストしました:

Sub addshapewithtext() 
    Dim BlankFound As Boolean 
    Dim x As Long 
    Dim w As Worksheet 
    Dim s As Shape 
    Dim t As Variant 

    x = 1 
    Do Until Cells(x, "A").Value = "" 
     Set t = Cells(x, "d") 
     Set w = ActiveSheet 
     Set s = w.Shapes.AddShape(msoShapeFlowchartProcess, 200 + x * 200, 100, 100, 100) 
     'format shape 
     s.Fill.ForeColor.RGB = RGB(300, 300, 300) 
     s.Line.ForeColor.RGB = RGB(0, 0, 0) 
     s.Line.Weight = 3 
     'transparency 
     s.Fill.Transparency = 0 
     'add text from list 
     s.OLEFormat.Object.Text = t 
     If Cells(x, "A").Value = "" Then BlankFound = True 
     x = x + 1 
    Loop 
End Sub 
+0

ありがとうございます!これは役に立ちます。私はまだプロセスブロックに表示するテキストを取得していません。 – ltcws1

+0

フォントは背景と同じ色ですからです。私の答えでは、私は何かwirhフォントサイズと色を行うことをお勧めします。テキストはそこにあります – KacireeSoftware

0

私の前の答えのコードは素晴らしいですが、テキストが白いので表示されません。あなたがそれらに色を与えることができ、プロセス・ブロック内のテキストを表示するには : s.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 0, 0)

コード:

Sub addshapewithtext() 
Dim BlankFound As Boolean 
Dim x As Long 
Dim w As Worksheet 
Dim s As Shape 
Dim t As Variant 

x = 1 
Do Until Cells(x, "A").Value = "" 
    Set t = Cells(x, "d") 
    Set w = ActiveSheet 
    Set s = w.Shapes.AddShape(msoShapeFlowchartProcess, 200 + x * 200, 100, 100, 100) 
    'format shape 
    s.Fill.ForeColor.RGB = RGB(300, 300, 300) 
    s.Line.ForeColor.RGB = RGB(0, 0, 0) 
    s.Line.Weight = 3 
    'Add color to text in process block 
    s.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 0, 0) 

    'transparency 
    s.Fill.Transparency = 0 
    'add text from list 
    s.OLEFormat.Object.Text = t 
    If Cells(x, "A").Value = "" Then BlankFound = True 
    x = x + 1 
Loop 

End Sub