2017-04-11 3 views
0

私はいくつかの選択されたテキスト(ページよりも長い)から関連情報をフィルタリングするマクロを作成しようとしています。この情報は、MS-Wordテンプレートの記入に使用されます。複数の行を入力としてテキスト選択を行うことができるVBAで '入力ボックス'を作成することはできますか?

選択したテキストを.txtファイルで開きましたが、&をコピーして入力ボックスの何らかの形に貼り付けることができればワークフローが改善されると思います。

私は次のことを試してみました:

Dim text As String 
text = InputBox("Enter selected text here:") 

これが唯一の文字列(1行のテキスト)受け入れます。

おかげで、Donfernanado

+1

私たちを作成する必要がありますエルフォーム。 –

答えて

0

リッチホルトンが指摘したように、あなたが希望する機能をサポートし、独自のInputBoxを作成することができます。

まずInputBox関数のように見えるユーザーフォームを作成します。私のものはCustomInputBoxです。

TextBoxのMultiLineプロパティをTrueに設定します。

例:

MessageBox Example

次にボタンのためのいくつかのロジックおよびプロンプトとタイトルのようないくつかのパラメータを取り、あなたのInputBox関数を表示する機能を追加します。

Option Explicit 

Private inputValue As String 
Private Cancel As Boolean 

Private Sub btnCancel_Click() 
    Cancel = True 
    Me.Hide 
End Sub 

Private Sub btnOK_Click() 
    If Me.txtInput.Value <> "" Then 
     inputValue = Me.txtInput.Value 
    End If 
    Me.Hide 
End Sub 

'This is the Function you are going to use to open your InputBox 
Public Function Display(Prompt As String, Optional Title As String = "", Optional Default As String = "") As String 
Cancel = False 

Me.lblPrompt.Caption = Prompt 

If Title <> "" Then 
    Me.Caption = Title 
Else 
    Me.Caption = "Microsoft Excel" 
End If 

If Default <> "" Then 
    Me.txtInput.Value = Default 
Else 
    Me.txtInput.Value = "" 
End If 

Me.txtInput.SetFocus 
Me.Show vbModal 

If Not Cancel Then 
    Display = inputValue 
Else 
    Display = "" 
End If 
End Function 

は今、あなたはすることができます次のように入力ボックスを使用してください:

Dim text As String 
text = CustomInputBox.Display("Enter selected text here:") 
関連する問題