我是一名英语老师,试图让自己熟悉VBA。我在下面使用以下代码在文本中的某些单词下划线,但是我在使用max时遇到了问题。字符串大小为255。
我想增加字符串的大小以在单个字符串中添加更多单词(更精确的说是700个)。
我找到了这个项目Getting around the Max String size in a vba function?,但是我不知道如何在我的代码中实现它。
Sub ListChange()
Dim r As Range
Dim MyList() As String
Dim i As Long
MyList = Split("segregation,investigation,treaty,accommodate,inheritance,tentative,utter,hijack,redundant,disrupt,conserve,lawsuit,graduate,handle,resolution,bewildered,fuss,confident,disguise,considerable,persistent,obligatory,expenses,initially,lecture,reluctance,extinct,toxic,precede,demolition,turnup,gap,disturb,independent,nerve,jusitification,turnout,compulsory,gathering,merciless,HomeOffice,impress,decline,diminish,essentially,deceive,advance,ambiguous,disposeof,disdain,apt,effort,famine,entirely,familiar,elderly,solution,commute,disproportionally,urge,obedience,retreat,merely,relief,distraction,principal,sanity,distortion,figure", ",")
For i = 0 To UBound(MyList())
Set r = ActiveDocument.Range
With r.Find
.Text = MyList(i)
.Replacement.Font.Underline = wdUnderlineSingle
.Execute Replace:=wdReplaceAll
End With
Next
End Sub
我想在一个字符串中获得更多字符。
答案 0 :(得分:0)
我不确定String数组是否有这样的限制,尽管VBA对每行的长度都有限制。您可以通过在末尾添加下划线'_'来继续同一条语句。
下面是您子例程的修改版本,我可以创建一个长句子(将您的句子粘贴多次),并且能够生成700多个单词。
Sub ListChange()
Dim r As Range
Dim MyList() As String
Dim i As Long
MyList = Split("segregation,investigation,treaty,accommodate,inheritance,tentative,utter,hijack,redundant,disrupt,conserve,lawsuit,graduate,handle,resolution,bewildered,fuss,confident,disguise,considerable,persistent,obligatory,expenses,initially,lecture,reluctance,extinct,toxic,precede,demolition,turnup,gap,disturb,independent,nerve,jusitification,turnout,compulsory,gathering,merciless,HomeOffice,impress,decline,diminish,essentially,deceive,advance,ambiguous,disposeof,disdain,apt,effort,famine,entirely,familiar,elderly,solution,commute,disproportionally,urge,obedience,retreat,merely,relief,distraction,principal,sanity,distortion,figure,welcome,world,hello,modification,activedocument,microsoft,hours,terminate,five,six,retinaeye,display,english,increase, " _
& "segregation , investigation, treaty, accommodate, inheritance, tentative, utter, hijack, redundant, disrupt, conserve, lawsuit, graduate, Handle, resolution, bewildered, fuss, confident, disguise, considerable, persistent, obligatory, expenses, initially, lecture, reluctance, extinct, toxic, precede, demolition, turnup, Gap, disturb, independent, nerve, jusitification, turnout, compulsory, gathering, merciless, HomeOffice, impress, decline, diminish, essentially, deceive, advance, ambiguous, disposeof, disdain, apt, effort, famine, entirely, familiar, elderly, solution, commute, disproportionally, urge, obedience, retreat, merely, relief, distraction, principal, sanity, distortion, figure, welcome, world, hello, modification, activedocument, microsoft, hours, Terminate, five, tw0" _
& "segregation , investigation, treaty, accommodate, inheritance, tentative, utter, hijack, redundant, disrupt, conserve, lawsuit, graduate, Handle, resolution, bewildered, fuss, confident, disguise, considerable, persistent, obligatory, expenses, initially, lecture, reluctance, extinct, toxic, precede, demolition, turnup, Gap, disturb, independent, nerve, jusitification, turnout, compulsory, gathering, merciless, HomeOffice, impress, decline, diminish, essentially, deceive, advance, ambiguous, disposeof, disdain, apt, effort, famine, entirely, familiar, elderly, solution, commute, disproportionally, urge, obedience, retreat, merely, relief, distraction, principal, sanity, distortion, figure, welcome, world, hello, modification, activedocument, microsoft, hours, Terminate, five, days" _
& "segregation , investigation, treaty, accommodate, inheritance, tentative, utter, hijack, redundant, disrupt, conserve, lawsuit, graduate, Handle, resolution, bewildered, fuss, confident, disguise, considerable, persistent, obligatory, expenses, initially, lecture, reluctance, extinct, toxic, precede, demolition, turnup, Gap, disturb, independent, nerve, jusitification, turnout, compulsory, gathering, merciless, HomeOffice, impress, decline, diminish, essentially, deceive, advance, ambiguous, disposeof, disdain, apt, effort, famine, entirely, familiar, elderly, solution, commute, disproportionally, urge, obedience, retreat, merely, relief, distraction, principal, sanity, distortion, figure, welcome, world, hello, modification, activedocument, microsoft, hours, Terminate, five, days" _
& "segregation , investigation, treaty, accommodate, inheritance, tentative, utter, hijack, redundant, disrupt, conserve, lawsuit, graduate, Handle, resolution, bewildered, fuss, confident, disguise, considerable, persistent, obligatory, expenses, initially, lecture, reluctance, extinct, toxic, precede, demolition, turnup, Gap, disturb, independent, nerve, jusitification, turnout, compulsory, gathering, merciless, HomeOffice, impress, decline, diminish, essentially, deceive, advance, ambiguous, disposeof, disdain, apt, effort, famine, entirely, familiar, elderly, solution, commute, disproportionally, urge, obedience, retreat, merely, relief, distraction, principal, sanity, distortion, figure, welcome, world, hello, modification, activedocument, microsoft, hours, Terminate, five, days" _
& "segregation , investigation, treaty, accommodate, inheritance, tentative, utter, hijack, redundant, disrupt, conserve, lawsuit, graduate, Handle, resolution, bewildered, fuss, confident, disguise, considerable, persistent, obligatory, expenses, initially, lecture, reluctance, extinct, toxic, precede, demolition, turnup, Gap, disturb, independent, nerve, jusitification, turnout, compulsory, gathering, merciless, HomeOffice, impress, decline, diminish, essentially, deceive, advance, ambiguous, disposeof, disdain, apt, effort, famine, entirely, familiar, elderly, solution, commute, disproportionally, urge, obedience, retreat, merely, relief, distraction, principal, sanity, distortion, figure, welcome, world, hello, modification, activedocument, microsoft, hours, Terminate, five, days" _
& "segregation , investigation, treaty, accommodate, inheritance, tentative, utter, hijack, redundant, disrupt, conserve, lawsuit, graduate, Handle, resolution, bewildered, fuss, confident, disguise, considerable, persistent, obligatory, expenses, initially, lecture, reluctance, extinct, toxic, precede, demolition, turnup, Gap, disturb, independent, nerve, jusitification, turnout, compulsory, gathering, merciless, HomeOffice, impress, decline, diminish, essentially, deceive, advance, ambiguous, disposeof, disdain, apt, effort, famine, entirely, familiar, elderly, solution, commute, disproportionally, urge, obedience, retreat, merely, relief, distraction, principal, sanity, distortion, figure, welcome, world, hello, modification, activedocument, microsoft, hours, Terminate, five, days" _
& "segregation , investigation, treaty, accommodate, inheritance, tentative, utter, hijack, redundant, disrupt, conserve, lawsuit, graduate, Handle, resolution, bewildered, fuss, confident, disguise, considerable, persistent, obligatory, expenses, initially, lecture, reluctance, extinct, toxic, precede, demolition, turnup, Gap, disturb, independent, nerve, jusitification, turnout, compulsory, gathering, merciless, HomeOffice, impress, decline, diminish, essentially, deceive, advance, ambiguous, disposeof, disdain, apt, effort, famine, entirely, familiar, elderly, solution, commute, disproportionally, urge, obedience, retreat, merely, relief, distraction, principal, sanity, distortion, figure, welcome, world, hello, modification, activedocument, microsoft, hours, Terminate, five, days" _
& "segregation , investigation, treaty, accommodate, inheritance, tentative, utter, hijack, redundant, disrupt, conserve, lawsuit, graduate, Handle, resolution, bewildered, fuss, confident, disguise, considerable, persistent, obligatory, expenses, initially, lecture, reluctance, extinct, toxic, precede, demolition, turnup, Gap, disturb, independent, nerve, jusitification, turnout, compulsory, gathering, merciless, HomeOffice, impress, decline, diminish, essentially, deceive, advance, ambiguous, disposeof, disdain, apt, effort, famine, entirely, familiar, elderly, solution, commute, disproportionally, urge, obedience, retreat, merely, relief, distraction, principal, sanity, distortion, figure, welcome, world, hello, modification, activedocument, microsoft, hours, Terminate, five, stack" _
& "segregation , investigation, treaty, accommodate, inheritance, tentative, utter, hijack, redundant, disrupt, conserve, lawsuit, graduate, Handle, resolution, bewildered, fuss, confident, disguise, considerable, persistent, obligatory, expenses, initially, lecture, reluctance, extinct, toxic, precede, demolition, turnup, Gap, disturb, independent, nerve, jusitification, turnout, compulsory, gathering, merciless, HomeOffice, impress, decline, diminish, essentially, deceive, advance, ambiguous, disposeof, disdain, apt, effort, famine, entirely, familiar, elderly, solution, commute, disproportionally, urge, obedience, retreat, merely, relief, distraction, principal, sanity, distortion, figure, welcome, world, hello, modification, activedocument, microsoft, hours, Terminate, five, one", ", ")
For i = 0 To UBound(MyList())
Debug.Print (MyList(i))
Next
Debug.Print ("No of words found in sentence " & UBound(MyList()) + 1)
End Sub
注意::我仅打印单词(删除了部分代码)。希望这就是您想要的。.