克服 VBA 输入框字符限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2969516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Overcome VBA InputBox Character Limit
提问by Ryan B
The current function I use to collect text InputBox can't accept more than 255 characters apparently, and I need to be able to collect more than that? Is there a parameter or different function I can use to increase this limit?
我用来收集文本的当前函数 InputBox 显然不能接受超过 255 个字符,我需要能够收集更多?我可以使用参数或不同的函数来增加此限制吗?
采纳答案by BradC
To be pedantic, the Inputbox will let you type up to 255 characters, but it will only return 254 characters.
为了学究,输入框最多可让您输入 255 个字符,但它只会返回 254 个字符。
Beyond that, yes, you'll need to create a simple form with a textbox. Then just make a little "helper function" something like:
除此之外,是的,您需要创建一个带有文本框的简单表单。然后只需制作一个小“辅助功能”,例如:
Function getBigInput(prompt As String) As String
frmBigInputBox.Caption = prompt
frmBigInputBox.Show
getBigInput = frmBigInputBox.txtStuff.Text
End Function
or something like that...
或类似的东西...
回答by Ryan B
Thanks BradC for the info that. My final code was roughly as follows, I have a button that calls the form that I created and positions it a bit as I was having some issues with the form being in the wrong spot the everytime after the first time I used.
感谢 BradC 提供的信息。我的最终代码大致如下,我有一个按钮调用我创建的表单并将其定位,因为我在第一次使用后每次都遇到表单位于错误位置的问题。
Sub InsertNotesAttempt()
NoteEntryForm.Show
With NoteEntryForm
.Top = 125
.Left = 125
End With
End Sub
The userform was a TextBox and two CommandButtons(Cancel and Ok). The code for the buttons was as follows:
用户窗体是一个文本框和两个命令按钮(取消和确定)。按钮的代码如下:
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
回答by sweBers
I don't have enough rep to comment, but in the sub form_load for the helper you can add:
我没有足够的代表来评论,但在助手的子 form_load 中,您可以添加:
me.AutoCenter = True
Outside of that form, you can do it like this:
在该表单之外,您可以这样做:
NoteEntryForm.Show
Forms("NoteEntryForm").AutoCenter = True
My Access forms get all confused when I go from my two extra monitors at work to my one extra monitor at home, and are sometimes lost in the corner. This AutoCenter has made it into the form properties of every one of my forms.
当我从工作时多出的两台显示器转到家里多出的一台显示器时,我的 Access 表单变得很混乱,有时会迷失在角落里。这个 AutoCenter 使它成为我的每一个表单的表单属性。