2010-06-03 109 views
5

我用來收集文本InputBox的當前函數顯然不能接受超過255個字符,而且我需要能夠收集比這更多的東西?是否有一個參數或不同的功能可以用來增加此限制?克服VBA輸入框字符限制

+1

爲什麼使用InputBox?小型表單和文本框幾乎總是一個更好的主意。 – Fionnuala 2010-06-03 20:31:02

+0

@Remou〜因爲這需要更多的代碼,並且對於新開發人員來說並不總是很容易使用,而InputBox具有高度的可訪問性。否則+1 – jcolebrand 2010-06-03 20:33:57

+0

〜我不認爲這會花費更長的字符串,SOL ...按照@ Remou的建議。 – jcolebrand 2010-06-03 20:34:21

回答

4

要迂迴,Inputbox將允許您鍵入最多255個字符,但它只會返回254個字符。

除此之外,是的,你需要創建一個帶有文本框的簡單表單。接下來,只要一點點「輔助函數」是這樣的:

Function getBigInput(prompt As String) As String 
    frmBigInputBox.Caption = prompt 
    frmBigInputBox.Show 
    getBigInput = frmBigInputBox.txtStuff.Text 
End Function 

或類似的東西...

+0

不應該像這樣''frmBigInputBox.myLabel.caption = prompt'這樣的標籤,否則一切都在窗體/窗口的頂部欄中。 – mountainclimber 2017-09-11 15:34:09

2

感謝BradC的信息說。我的最終代碼大致如下,我有一個按鈕,用於調用我創建的表單,並定位它,因爲我在第一次使用後每次都發現表單存在一些問題。

Sub InsertNotesAttempt() 
    NoteEntryForm.Show 
    With NoteEntryForm 
     .Top = 125 
     .Left = 125 
    End With 
End Sub 

userform是一個TextBox和兩個CommandButtons(Cancel和Ok)。對於按鈕的代碼如下:

Private Sub CancelButton_Click() 
    Unload NoteEntryForm 
End Sub 

Private Sub OkButton_Click() 
    Dim UserNotes As String 

    UserNotes = NotesInput.Text 

    Application.ScreenUpdating = False 
    If UserNotes = "" Then 
     NoteEntryForm.Hide 
     Exit Sub 
    End If 

    Worksheets("Notes").ListObjects("Notes").ListRows.Add (1) 
    Worksheets("Notes").Range("Notes").Cells(1, 1) = Date 
    Worksheets("Notes").Range("Notes").Cells(1, 2) = UserNotes 
    Worksheets("Notes").Range("Notes").Cells(1, 2).WrapText = True 
    ' Crap fix to get the wrap to work. I noticed that after I inserted another row the previous rows 
    ' word wrap property would kick in. So I just add in and delete a row to force that behaviour. 
    Worksheets("Notes").ListObjects("Notes").ListRows.Add (1) 
    Worksheets("Notes").Range("Notes").Item(1).Delete 
    NotesInput.Text = vbNullString 
    NotesInput.SetFocus ' Retains focus on text entry box instead of command button. 
    NoteEntryForm.Hide 
    Application.ScreenUpdating = True 
End Sub 
1

我沒有足夠的代表處發表評論,但在子的Form_Load的助手,你可以添加:

me.AutoCenter = True 

之外的形式,你可以做這樣的:

NoteEntryForm.Show 
Forms("NoteEntryForm").AutoCenter = True 

我的訪問形式讓所有困惑,當我從我的兩個額外的顯示器去上班時我一個額外的顯示器在家裏,並在角落裏有時會丟失。這個AutoCenter已經將它變成了我的每一個表單的表單屬性。

+0

歡迎來到本網站!如你所知,這不會嘗試回答發佈的問題,而應該是一條評論。 [請僅使用Answers來回答問題](// meta.stackoverflow.com/q/92107)。要批評或要求作者澄清,在他們的帖子下留下評論 - 你總是可以評論你自己的帖子,一旦你有足夠的聲譽(// stackoverflow.com/help/whats-reputation),你將能夠[評論任何帖子](// stackoverflow.com/help/privileges/comment)。同時,請不要使用回覆來發表評論。 – Mogsdad 2016-05-13 14:05:03