#1
|
|||
|
|||
Mistake in the help file for String "Split Function"?
Is there a mistake/typo in the help file here:
Split function (Visual Basic for Applications) | Microsoft Docs Should "arrSplitStrings1()" and "arrSplitStrings2()" not be declared as Strings rather than Variants? Code:
Sub Demo2() Dim strFull As String Dim arrSplitStrings1() As Variant Dim arrSplitStrings2() As Variant Dim str1 As String, str2 As String, str3 As String Dim i As Long ' String that will be used: strFull = "Some - Old - Hags - Can - Always - Hide - Their - Old - Age" arrSplitStrings1 = Split(strFull, "-") arrSplitStrings2 = Split(strFull, " - ") str1 = arrSplitStrings2(3) ' str1 = "Can". str2 = Split(strFull, " - ")(3) ' str2 = "Can". For i = LBound(arrSplitStrings2, 1) To UBound(arrSplitStrings2, 1) If InStr(1, arrSplitStrings2(i), "Can", vbTextCompare) > 0 Then str3 = arrSplitStrings2(i) Exit For End If Next i End Sub |
#2
|
||||
|
||||
It is best not to use variants unless needed, as they require more memory than other data types.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks Macropod. But is it not more significant than a matter of efficiency? By declaring them as Variants the macro appears not to work. I get "Runtime error '13': Type mismatch".
|
#4
|
||||
|
||||
I see what you mean. They should be declared as strings.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Hopefully one of you can pass that on to Microsoft for the benefit of other novices like myself. Using that help file as a guide for my own macro, I spent two very frustrating hours trying to figure out what was wrong with my code.
Thank you though for quick replies and for clearing that up for me. Last edited by John 4; 11-19-2020 at 05:54 AM. |
#6
|
||||
|
||||
This forum has no affiliation with Microsoft.
You could make a suggestion for the change at Welcome to Word's Suggestion Box!.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Thanks Paul. I'm aware of that; I just thought they'd be more likely to listen to someone like you than someone like me. And I still think so
But I'll let them know. My apologies also if my last post seemed angrier than I intended. I've edited it a little to make it less so. Thanks for all your help. |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Replace " in string sent to output file | gedinfo2020 | Word VBA | 3 | 02-27-2020 02:30 PM |
"Split apart page break and paragraph mark" setting | harry | Word | 10 | 12-18-2019 07:08 PM |
Keyboard toggle for switching between two split "screens" in Word 2010 | BAEngelTranslations | Word | 4 | 10-26-2015 04:44 AM |
When Outlook starts, a warning box "String was not recognized as a valide datetime" | twormington | Outlook | 4 | 02-03-2014 11:01 PM |
Macro VBA "Save as" with bookmarks in file name string | Dom37 | Word VBA | 2 | 10-31-2011 03:28 AM |