2016-04-07 11 views
0

ユーザーが情報を入力できるGUIにテキストボックスを設定しました。この文字列は、PPTスライド内のテキストボックスに吐き出されます。 PPTスライド内のテキストボックスで使用されている行数に応じて、テキストボックスのテキストの下に新しい行がたくさんあるので、次の情報セットを入力する必要があります。ここで私はこれまで持っているものです。VBAのテキストボックス内の行数を調べる

これにより、ユーザはGUI内のテキストボックスに入力し、PPTスライド内のテキストボックスにそれを置き、テキストを取るコードです:

Private Sub Location() 

    With ActiveWindow.Selection.SlideRange.Shapes("WarningData").TextFrame2 
    'Make sure there is text in the call to action textbox. If not, display an error message. 
    If C2AText = "" Then 
     MsgBox "Woah there! You need to enter text in the location/call to action box." 
    'Otherwise, if text is inserted, place that text in the WarningData box found on the PPT slide. 
    Else 
     .TextRange = C2AText 
     .TextRange.Paragraphs.Font.Size = 21 
     .TextRange.Paragraphs.Font.Name = "Calibri" 
     .TextRange.Paragraphs.Font.Shadow.Visible = True 
     .TextRange.Paragraphs.Font.Bold = msoTrue 
    End If 
    End With 

End Sub 

このテキストは決定HailInfoドロップダウンで何かが選択されているかどうか。もしそうであれば、私はこのテキストを配置する必要があるので、前のサブに挿入したC2AText以下の行数:

Private Sub HailInfo() 
Call Dictionary.HailInfo 

ComboBoxList = Array(CStr(HailDropDown)) 

    For Each Ky In ComboBoxList 
    'On Error Resume Next 
    With ActiveWindow.Selection.SlideRange.Shapes("WarningData").TextFrame2 
     'If nothing is selected in HailDropDown, do nothing and exit this sub. 
     If HailDropDown = "" Then 
     Exit Sub 
     'If a hail option is selected, execute the following code. 
     ElseIf HailDropDown <> "" And C2AText.LineCount = 2 Then 
     .TextRange = .TextRange & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & dict2.Item(Ky)(0) 
     ElseIf HailDropDown <> "" And C2AText.LineCount = 3 Then 
     .TextRange = .TextRange & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & dict2.Item(Ky)(0) 
     End If 
    End With 
    Next 

    Set dict2 = Nothing 

End Sub 

C2AText.LineCountを使用してHailInfoサブ内には、何もする表示されません。雹のテキストはどこにも挿入されないので、私は何が間違っているのか分かりません。どんな助けでも大歓迎です...ありがとう!!

答えて

0

あなたは...

Private Sub HailInfo() 
Call Dictionary.HailInfo 

ComboBoxList = Array(CStr(HailDropDown)) 

    For Each Ky In ComboBoxList 
    'On Error Resume Next 
    With ActiveWindow.Selection.SlideRange.Shapes("WarningData").TextFrame2 
     'If nothing is selected in HailDropDown, do nothing and exit this sub. 
     If HailDropDown = "" Then 
     Exit Sub 
     'If a hail option is selected, execute the following code. 
     Else 
     .TextRange.Text = .TextRange.Text & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & dict2.Item(Ky)(0) 
     End If 
    End With 
    Next 

    Set dict2 = Nothing 

End Sub 

あなただけではなく.TextRange.Textよりも、.TextRangeを参照して以下のことを試してみてください。

また、最後にテキストを追加する必要があるので、同じものを実行する2つのElseIfではなく、Elseの条件が必要です。 ; 0)


よりサンプルコードを... https://msdn.microsoft.com/en-us/library/office/ff822136.aspx

+0

おかげで、しかしそれら二つのElseIfステートメントは、二つの異なることを行うことになっています。ユーザーは、C2ATextに入力されたテキストの行数に基づいて、異なる数の改行(vbCrLF)を挿入します。 – hunter21188

+0

あなたが指定したコードでは、どちらもまったく同じことをしています! –

+0

ああ!良いキャッチ。実際には、それぞれに異なる数のvbCrLFが存在します。 – hunter21188

関連する問題