PDA

View Full Version : ब्लॉग कोशिश कर रहा है بلاگز کی ک*Trying Blogs



DocAElstein
02-07-2017, 03:10 AM
Trying Blogs ब्लॉग कोशिश कर रहा है ബ്ലോഗുകൾ ശ്രമിക്കുന്നു

بلاگز کی کوشش کر رہے



The purpose of this Thread is the following:
इस धागे के उद्देश्य निम्नलिखित है:
ഈ ത്രെഡ് ഉദ്ദേശ്യം പിന്തുടരുന്നു:

:یہاں مقصد مندرجہ ذیل ہے


Codes and Information is here.
संहिताओं और सूचना यहाँ हैं।
കോഡുകൾ സമവാക്യങ്ങളേയും വിവരങ്ങൾ ഇവിടെ ഉണ്ട്.

کوڈز اور معلومات یہاں پایا جائے.


1)
To be referenced in this web site
इस वेब साइट में संदर्भित किया जा करने के लिए
ഈ വെബ് സൈറ്റിൽ പരാമർശിച്ചിരിക്കുന്ന ലഭിക്കണമെങ്കിൽ

ان خطوط اس ویب سائٹ سے محولہ کیا جائے گا

2)
Also to be referenced from other web sites
इसके अलावा अन्य वेब साइटों से संदर्भित किया जा करने के लिए
മറ്റ് വെബ് സൈറ്റുകളിൽ നിന്നുള്ള പരാമർശിച്ചിരിക്കുന്ന ചെയ്യുവാൻ

اس کے علاوہ دیگر ویب سائٹس سے محولہ کیا جا کرنے

_...........
This has been agreed with the Administrator
यह व्यवस्थापक द्वारा सहमति व्यक्त की है
ഈ അഡ്മിനിസ്ട്രേറ്റർ സമ്മതിച്ചു ഉണ്ടായിരുന്നു

یہ ایڈمنسٹریٹر کی طرف سے اس بات پر اتفاق کیا ہے

http://www.excelfox.com/forum/showthread.php/2058-Just-testing-a-before-a-possible-Thread-post-No-reply-needed#post10071
http://www.excelfox.com/forum/showthread.php/2058-Just-testing-a-before-a-possible-Thread-post-No-reply-needed/page2#post10082

http://www.excelfox.com/forum/showthread.php/2058-Just-testing-a-before-a-possible-Thread-post-No-reply-needed#post10071
http://www.excelfox.com/forum/showthread.php/2058-Just-testing-a-before-a-possible-Thread-post-No-reply-needed/page2#post10082


There are no restrictions on posting here
यहां पोस्टिंग पर कोई प्रतिबंध नहीं कर रहे हैं
ഇവിടെ പോസ്റ്റുചെയ്യുന്നതിന് നിയന്ത്രണങ്ങൾ ഒന്നുമില്ല

یہاں پوسٹنگ پر کوئی پابندی نہیں ہے

There is no time limit on Editing ( Only here in Test Sub Forum )
संपादन पर कोई समय सीमा नहीं है ( केवल परीक्षण उप फोरम में )
എഡിറ്റിംഗ് യാതൊരു സമയ പരിധിയുമില്ല ( മാത്രം ഉപ ഫോറം ടെസ്റ്റ് )

ترمیم پر کوئی وقت کی حد نہیں ہے
( صرف ذیلی فورم ٹیسٹ )

I will re use some posts. By Editing. There is no time limit on Editing
मैं फिर से उपयोग होगा कुछ पदों . बदलें संपादन . संपादन पर कोई समय सीमा नहीं है.
ഞാൻ ചില ഭാഗങ്ങളിൽ പുനരുപയോഗിക്കാൻ ചെയ്യും. എഡിറ്റ് സാധ്യമാണു് . എഡിറ്റിംഗ് യാതൊരു സമയ പരിധിയുമില്ല

ترمیم پر کوئی وقت کی حد نہیں ہے میں ترمیم کو استعمال کرتے ہوئے I ادلیکھت کبھی کبھی کریں گے بنانے کے.


Alan
:)

_.________________________________________________ _______________________

Quick links
Variable definitions : http://www.excelfox.com/forum/showthread.php/2157-Re-Defining-multiple-variables-in-VBA?p=10192#post10192

DocAElstein
02-11-2017, 10:22 PM
VBA Remove BB Code Code Tags in text

In the next post is a code to remove BB Code Code Tags in text

This code is slightly redundant since I was given a simpler one ,
http://www.eileenslounge.com/viewtopic.php?f=26&t=26030&p=202145#p202122
which probably is more Full proof !
But I include it here with description for future reference. I may use it in a following code or codes to cross check the results given.
The code is intended to remove valid BB Code Code Tag sections from a Text string.
In this case, valid means in terms of the syntax, which is basically as follows

Any text or Any text

An arbitrary string is given initially in code section Rem 1)
"gggg245[/8]x[dddAny text"


Then the main code is as follows

Rem 2 Brief Code description
The code works backwards 100 through the whole string. It looks at a character at a time.
120 __ On If finding a ] , it notes the position of it,
140 BcrdEEnd, then keeps going back.
160___If it finds another it notes that as the ] position and carries on going back.
170 It determines the position of a [ , BcrdESt, by looking for a [\
It starts looking again for the next ] ,
250 _____If a ] is found, it checks
260 _____If the next character back is another ], Then it keeps going back. If the next character back was Not a ] , then the position of the ], BcrdSEnd, is
270 noted
A new last loop 290 starts going further back to look for a [
300 ________If it finds a [ , it notes that, BcrdSSt.
320 ________If in the unlikely event that it is a start of an end , like [\ then we have found a second End BB Code Code Tag so we do like_..
BcrdEEnd = BcrdSEnd:
BcrdESt = BcrdSSt:
BcrdSEnd=0:
( BcrdSSt=0 )
_..and go back and start again looking for the start tag. Otherwise the start position of the start tag, BcrdSSt, is noted, then it is finally time to go and think about getting rid of the code tag pair whose positions have now been determined....
430 FkOffCrd:
_..So I come to a point, aptly named, Rem 3) "I think we come here with a complete set of 4 positions". So I try to take the BB Code Code Tags out. As I am going backwards, the new string with the missing Code Tag pair does not mess up me going through the characters as I took off stuff “behind me”
450 I overdo the use of variables here because I can and do, but also because a development of the code might be to look through a list of available BB Code Code Tags to check I have them . I do one quick validity check: I check that the word after the / in the End BB Code code tag is the same as the word in the start BB Code code tag ( that before an = , if there is an = ) . Only
500____ If this condition ( which must be met for a valid BB Code code tag ) is met are the pair of tags removed by replacing them with , . Another condition is also checked: a / in second character of the stop tag.

Either from going through a code section search with possible removal, or ,
540 Else not , we are at the Next posCurrent of the main going backward Loop,
580 , so keep going back looking for another, or a first possible start ( looking from the back ).
Hopefully, for example at line 340, posCurrent would have been reduce to allow for the inner Loops going back in a code tag section search.


_................................

The code returns the string:
gggg245[/8]x[dddAny text

DocAElstein
02-11-2017, 10:31 PM
Code described and ExPlained in last post


Code described and ExPlained in last post
:rolleyes: I just said that :)



Sub LongWayOfDoingIt()
10 Rem 1) Test string
20 Dim strBBCode As String '
30 Let strBBCode = "gggg245[/8]x[ddd]Any text"
40 Dim strRmveBBCode As String: Let strRmveBBCode = strBBCode ' This will be adjusted until finally has no BBCode tag pairs
50 Dim Lstr As Long ' This will be adjusted as necerssary for current length ' Long is very simple to handle, - final memory "size" type is known (123.456 and 000.001 have same "size" computer memory ) , and so a Address suggestion can be given for the next line when the variable is filled in. '( Long is a Big whole Number limit (-2,147,483,648 to 2,147,483,647) If you need some sort of validation the value should only be within the range of a Byte/Integer otherwise there's no point using anything but Long.--upon/after 32-bit, Integers (Short) need converted internally anyways, so a Long is actually faster. )
60 Let Lstr = Len(strBBCode)
70 Rem 2) Loop through and get a BB Code section
80 Dim strBBCodePair As String ' for a found valid pair '
' Prepares "Pointer" to a "Blue Print" (or Form, Questionaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular “Value”, or (“Values” for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. A String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quich checks.. But..http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring-2.html#post44116
90 Dim posCurrent As Long 'Current position in the string' Loop Bound variable Count '_-Main Loop==========================
100 For posCurrent = Lstr To 2 Step -1 'Important to go backwards as we chop off behind us so have a less complicated current position. We look at pos-1 in some code parts so we would error if we went back to less than 2
110 '2a) Check for a ] Most likely a end of end tag ' ---Loop To find ]
120 If Mid(strRmveBBCode, posCurrent, 1) = "]" Then
130 Dim posBBCodeTagSrch As Long '
140 Dim BcrdEEnd As Long: Let BcrdEEnd = posCurrent 'Position of possible End Code Tag End ' ---Loop To Find [/--
150 For posBBCodeTagSrch = posCurrent - 1 To 2 Step -1 'PosCurrent is set here at loop start. ###It is not effected by cardinally sining changing PosCurrent Loop Bound variable caount in Outer main Loop
160 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "]" Then Let BcrdEEnd = posBBCodeTagSrch: GoTo NxtCESPosPos ' If we hit another ] then change the stop tag stop character position and start again to see if is a valid BB code section
170 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "/" And Mid(strRmveBBCode, posBBCodeTagSrch - 1, 1) = "[" Then 'We hit start of a BB Code end tag
180 Dim BcrdESt As Long: Let BcrdESt = posBBCodeTagSrch - 1 'Position of End Code Tag Start
190 Exit For ' We leave this For the End Code Tag Start Search, Exit For with a [ at posBBCodeTagSrch-1
200 Else 'Not found start of end Tag or stop of end Tag.
210 End If
220 NxtCESPosPos: Next posBBCodeTagSrch ' go back in possible BB code string ' ---End Loop to find [/---------------------
230 If posBBCodeTagSrch = 3 Then Exit Sub 'case we never found the start of an End Code Tag
235 '2b) Check for a ] Most Likely end of start tag ' ---Loop to find ]
240 For posBBCodeTagSrch = posBBCodeTagSrch - 2 To 2 Step -1 ' Once again ### the start is set and fixed, the Loop Bound Variable Count will change
250 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "]" Then
260 If Mid(strRmveBBCode, posBBCodeTagSrch - 1, 1) = "]" Then GoTo NxtCSSPosPos ' If we hit another ] then start again to see if is a valid BB code start section
270 Dim BcrdSEnd As Long: Let BcrdSEnd = posBBCodeTagSrch 'Position of possible Start Code Tag End
280 Dim LTagStLoop As Long 'Last loop to find start of start Code Tag
290 For LTagStLoop = posBBCodeTagSrch - 1 To 1 Step -1 '_-Most Inner loop_______to find [/____________
300 If Mid(strRmveBBCode, LTagStLoop, 1) = "[" Then
310 Dim BcrdSSt As Long 'Have to put it here, - I may occaisionally have to set it to 0 in next line
320 If Mid(strRmveBBCode, LTagStLoop + 1, 1) = "/" Then Let BcrdEEnd = BcrdSEnd: Let BcrdSEnd = 0: Let BcrdESt = LTagStLoop: Let BcrdSSt = 0: Let posBBCodeTagSrch = LTagStLoop: GoTo NxtCSSPosPos ' Found a second end Code Tag. So change the previous found start and stop , and adjust the Loop Bound variable Count appropriately for a new search for a start Code Tag
330 Let BcrdSSt = LTagStLoop
340 Let posCurrent = BcrdSSt 'End of Code Tag section search
350 GoTo FkOffCrd ' We leave this For the start Code Tag Start Search and go to Fuk Off Crd:
360 Else ' Still looking for start of start Code Tag
370 End If
380 Next LTagStLoop '_- End Most inner loop_____________________to find [/_____________________________
390 If LTagStLoop = 1 Then GoTo TheEnd 'Case I think we failed to find a start start [ for the complete possible Code Tag section search
400 Else 'Not found end of start Tag or start of start Tag
410 End If
420 NxtCSSPosPos: Next posBBCodeTagSrch ' go back in possible BB code string' ---End Loop to find ]
425 If posBBCodeTagSrch = 0 Then GoTo TheEnd ' For any outer search failed to find a ] at all or a search for matching start tag that was fruitless
430 FkOffCrd: Rem 3) "I think we come here with a complete set of 4 positions"
440 If BcrdEEnd <> 0 And BcrdESt <> 0 And BcrdSEnd <> 0 And BcrdSSt <> 0 Then 'Just to check'
450 Dim SttBcrd As String, StpBcrd As String ' Start and stop tags as coplete strings including [ and ]
460 Let SttBcrd = Mid(strRmveBBCode, BcrdSSt, BcrdSEnd - BcrdSSt + 1) ' ' like |Color=Red|
465 Let StpBcrd = Mid(strRmveBBCode, BcrdESt, BcrdEEnd - BcrdESt + 1) ' ' like |/Color|
470 Dim SttWrd As String, StpWrd As String
480 Let StpWrd = Mid(StpBcrd, 3, Len(StpBcrd) - 3) ' like Color from |/Color| - Whole Word, from 3rd Chr , for Length as WholeWord-3
490 Let SttWrd = Mid(SttBcrd, 2, Len(StpWrd)) ' like Color from |Color=Red|
500 If UCase(SttWrd) = UCase(StpWrd) And Mid(StpBcrd, 2, 1) = "/" Then 'Ucase allows for differences in cases And Mid(SttBcrd, Len(SttWrd) + 2, 1) = "=" Then
510 Let strRmveBBCode = Replace(strRmveBBCode, SttBcrd, "", 1, 1) ' Replace in ( strRmveBBCode , the start tag , with no string , start loooking from and return from character 1 )
515 Let strRmveBBCode = Replace(strRmveBBCode, StpBcrd, "", 1, 1)
520 Else 'No shortening of string for non matching tag word
530 End If
540 Else 'No shortening of string for not all 4 [ and ] found. Not sure if I ever come here..
550 End If
560 Else ' no last ] of a possible Code section yet, so keep going back down in the main string , main loop
570 End If
580 Next posCurrent '_-===Main Loop============================================== ==========================================
590 TheEnd:
600 MsgBox Prompt:="" & strRmveBBCode & "": Debug.Print "" & strRmveBBCode & "" 'Hit Ctrl+g when in VB Editor Window, reveal Immediate window after code run
End Sub

DocAElstein
02-14-2017, 04:39 AM
The VBA code in the last few posts is a bit of a long way around of doing what can be done in a Word Dialogue box type thing using Wild things:
http://www.gmayor.com/replace_using_wildcards.htm
http://imgur.com/4Nqj1HP

The problem is getting at the Wild Things needed in the Wild Find String.

I can’t do it. But Hans and Paul did it for me here:
http://www.eileenslounge.com/viewtopic.php?f=26&t=26030#p202107

Here is my attempt at an ‘ExPlanation of the solution:


Wild Things. You make my heart sing. They make everything….. Groovy

Wild Things. You make my heart sing. They make everything….. Groovy
http://listenonrepeat.com/watch/?v=Hce74cEAAaE#The_Troggs_-_Wild_Thing
Wild things…. I think I hate you .. But I wanna know for sure… so

A Summary :)
As example. We want to remove the start and stop tags in a sample string containing a start and stop tag such as this_..

This is green This ‘aint matey

_.. What we finally want is this:

This is green This ‘aint matey

We use a combination of Wild things , or like a pattern to search for [ Find ] any bits like _..

This is green
_.. and [ Replace ] that “Find”ed with

This is green

We can do, it Wildly, man, as follows:
As always the search is done from left to right

The way I do it below is probably not the most efficient way, in fact it is probably pretty stupid, but is just to demo the idea
Optional use of ( ) in the Wild thing search string
We can use brackets ( ) , optionally , to identify, ( for later use ) , the exact string parts found by the constituent Wild things in the ( ) in which they are in:
So in this example we will use a ( ) for
_ the Wild things that find the color so that the actual word color can be used again in the same wild stuff string, so as to make sure that we find in the end tag the matching word to that in the start tag.
_ Also we need a ( ) to identify the wild things that Find This is green , as we want to use that in , or rather for the complete, Replace string.
A bracket is identified by , for example, \2 if I want to reference the actual string found by the wild things we enclose in the second ( )

Build up final Wild thing Replace string, left to right, by breaking string we want up into bits. Each bit will be found by a Wild thing or things
So we are looking to break the to search for Wild [ Find ] Thing string down thus:

[ & ( AnythingWithout=or] ) & anything & ] & (Anything) & [\ & \1 & ]
So I am breaking it down in to 8 bits. So I need 8 sections of wild stuff to Find those.
\1 is at the 7th position and refers to what is actually found by the search for ( AnythingWithout=or] ) at position 2 ( which is bracket ( ) number 1 )


Excel starts at the left. What no literature really states clearly ( and is only obvious once you know it ) is this:
_ For most sections, Excel keeps going to the right until it Finds what the Wild thing tells it to. That is then stored, but only if that found string also has joined to it the string type in the next section’s Wild thing. Those two sections are then stored ( as well as storing separately if either of those two sections are enclosed in ( ) ), but only if that found string also has joined to it the string type in the next section’s Wild thing. That is then stored, but only if that found string also has joined to it the string type in the next section’s Wild thing. ……..etc.
A common Wild thing is * . This means anything characters and any amount. This will only include, however, anything up to if and when the next Wild thing is satisfied.

The 7th Wild thing I already have which is \1 which is referring to the 1st bit enclosed in a ( ) , which is the second bit in the broken up string , ( which is anything without a = or a ] . In our example this will be color) . Note: The number refers to the number from the left of any ( ) that I may have included, not the actual sections.
Just to make that last point clear, and to demonstrate another, I will do this_..

[ & ( AnthingWithout=or] ) & ( Anything & ] ) & (Anything) & [/ & \1 & ]
_.. so my Replace is then \3 . I do not need the second ( ___ ) , which I could reference by \2, ( and it can help to result in an “expression too complex” error ! ).
I put the second ( ___ ) in also to demo that a ( __ ) can include more than one wild bit



So here is one example Find sting with Wild things that “works” ( I added spaces to show better the 8 sections, but in use those spaces must be removed ). There are three optional ( ) sections. The second ( ) section encloses two Wild thing sections: Those are the third and forth counting from the left.


[\[] ([!\]=]@) (* \]) (*) \[/ (\1) \]
This is the actual Wild Find string
___ [\[]([!=\]]@)(*\])(*)\[/(\1)\]

To '_- ExPlain the 8 parts:
Part 1 [\[]
Excel start “looking” from the left to find a [
As a general rule Wild things are enclosed in a [ ] pair to identify them as such. So a [ ] is a Wild thing. They do not always have to be enclosed in a [ ], as is the case here. Here we are effectively looking to Find a single simple character, [.
( In the final Find string, only the second Wild section needs to be enclosed partly in a [ ] pair ).
So this section written as \[ instead is just as good. I suspect my use of the extra [ ] here does not have any bad effects, as it might be that the final string would be at compile or whatever reduced to \[ in either use of \[ or [\[]
We need to use the Wild thing, \ , quite a bit , in our total string for the same reason that we do here: This is because the \ has another use in Wild things in addition to the already discussed way like \7 ( where 7 would be for the 7th ( ) ). This other use of \ is to allow us to use characters as simple text which have a specific use in Wild things, so that Excel knows that we want to use them as their literal text string, rather than as Wild thing. Here it is needed for the first [ which we want to find.
( It follows that if we were looking for a \, then we would need to use \\ )
In our example string we find with this first Wild thing section the first [

Part 2 ([!\]=]@)
As noted the ( ) allows the string actually found in this Wild bit to be used later to the right via the reference \1.
As for this:
[!\]=]@ ( which could just as well be written [!=\]]@ )
We need a [ ] pair here, as within that is part of the Wild instructions for what to search for , and that has a further Wild instruction, @ , applied to that.
So in such a [ ] pair we would normally expect some specific wild stuff
Here the Wild thing, ! , means we search for any character other than those after included up to the closing tag ]. In our sample string , our first Wild bit found the first [ which now has added on any string at the next character if it is not a = or a ]
So this part of the second wild bit will find c in our sample string. If we had no other wild instructions here, then Excel would be content/ satisfied with that c. That would be joined on to the first [ found, so our result so far would be [c . In effect Excel stops going to the right when it is satisfied, and goes on to the next Wild bit. But we have another wild instruction here: The @ instructs to look for any amount of characters meeting the conditions before it, in this case the conditions in the [ ]. So the “Find” will stop finding characters when it no longer has a not = or a not ]. In our sample string the characters meeting the conditions are tacked on to a [ so will be will be =]@ has actually found and what the brackets ([!\]=]@) can be thought of as “holding” is color.
An alternative for @ would be {1,} which looks for between 1 and any amount of what is before it.
If we had used {1,4} or {2,4} instead of @ we would have so far for the complete found string [colo
If we had used {5,5} we would not have found a matching code tag word with less than 5 characters.

Parts 3 and 4 (*\])
This is unnecessarily in ( ) . *\] will do
The literature says * looks for any amount of anything. I think that is not strictly correct, or at least, explains it badly. It would appear to look for any amount of anything only until the next wild condition is met. That is why I chose to put it in ( ) just to demo the dependence, as it were. But this (*)(\]) or this *\] would work just as well (*)(\]).
Once again the \ is required for telling Excel that we want it to recognise ] as a string rather than a specific Wild thing. For this section , with my example string, I get from this complete 2 part Wild section
=green]
If our code tags were of the form like: ]SomeBoldText , then the search would have “stopped before it started”, as it were, as the ] would have “stopped” it
The combination of the 2 part Wild sections in this case would return just the single text character ]


Parts 5 and 6 (*)\[/
I contradict what I said in the last section slightly by using a ( ) around the * . Once again the * does nothing useful without the next wild bit to “stop” it. But what it does Find before it “stops” is what we actually need for Replace string. Hence I need a ( ) to reference what it Finds. This total Part 5 and part 6 section returns in our example
This is green[/
and the part referenced inside the ( ) is
This is green

Part 7 (\1)
As discussed already here the Wild thing, \1 , instructs to Find a string equal to that actual text found in the first ( ) if it is just before the next to be found ( which we will see in the next Part is the last character pair found, [/ ). The actual string found by [!\]=]@ in Part 2 , was , in our example the text color

Part 8 \]
Finally only a complete final Find attempt is successful if the last character is a ] , that is to say if the character after the text, in our example, the second color, is a ]

_...

The Final “Find”ed String for our example would be

[ & color & =Green & ] & This is green & [/ & color & ]

DocAElstein
02-14-2017, 05:35 AM
Here is a simple code to use the Find and Replace discussed in the last Post
The code should go in a code module in a WORD .docm File
Before rung the code, a text which includes BBCode Code Tags , should be selected in a Word document.

The Code makes a temporary File, "TempBBCodeCopy1.docx", holding the original selected text, then removes the BB Code Code Tags from the text and saves that as another temporary File, "TempNoBBCodeCopy2.docx"




Sub WegDaMitHansPaulAlan() ' http://www.eileenslounge.com/viewtopic.php?f=26&t=26030#p202223
Rem Code Part 1) make two temporary Word Files with and without BB Code
Rem 1) Copy selection to Clipboard
Selection.Copy
Rem 2) Make temporary WORD document
Documents.Add: ActiveDocument.Content.Paste
' 2b) Copy of Full Text with BB Code
Dim FullFilePathAndFullNameBBCode As String
ActiveDocument.SaveAs Filename:="TempBBCodeCopy1.docx", FileFormat:=wdFormatXMLDocument
Let FullFilePathAndFullNameBBCode = ActiveDocument.Path & "\" & ActiveDocument.Name
Rem 3) Replace Code tag pairs with what is in between
Selection.WholeStory
With Selection.Find
.ClearFormatting: .Replacement.ClearFormatting
.Wrap = wdFindStop
.MatchWildcards = True '
.Text = "[\[]([!=\]]@)(*\])(*)\[/(\1)\]" ' 8 sections, 4 identified with ( ) but I only need two ( )
.Replacement.Text = "\3" ' The third of the 4 sections identified with a ( )
.Execute Replace:=wdReplaceAll
End With
' 3b) Copy of Colored Text without BB Code Code tags
Dim FullFilePathAndFullNameNoBBCode As String
ActiveDocument.SaveAs Filename:="TempNoBBCodeCopy2.docx", FileFormat:=wdFormatXMLDocument
Let FullFilePathAndFullNameNoBBCode = ActiveDocument.Path & "\" & ActiveDocument.Name
Rem 4) "Reset the "Find Replace Text Dialogue" "Thing" "
ActiveDocument.Select
Selection.WholeStory
With Selection.Find
.ClearFormatting: .Replacement.ClearFormatting: .Text = "": .Replacement.Text = "": .Forward = True: .Wrap = wdFindAsk: .Format = False: .MatchCase = False: .MatchWholeWord = False: .MatchKashida = False: .MatchDiacritics = False: .MatchAlefHamza = False: .MatchControl = False: .MatchWildcards = False: .MatchSoundsLike = False: .MatchAllWordForms = False '
End With
Rem 5) Option to close / kill document
ActiveDocument.Close (wdDoNotSaveChanges)
'Kill FullFilePathAndFullNameBBCode
'Kill FullFilePathAndFullNameNoBBCode
End Sub ' End Code Part 1)

DocAElstein
02-20-2017, 05:21 PM
Full Code "Belt and Braces" in Word Find Replace & String Manipulation of initial Text String in Clipboard

This code is simply doing the two ways to remove BB Code code tag pairs from a copied to the clipboard Text from a Word document.
A check is then done Finally to see if the two raped from tags strings are the same.

I would not be surprised if a fail in the strings match just means that the second method, ( my long string manipulation way ) is getting it wrong.. Lol.. but never mind :) ***
***Edit: - like I just did: It will not work for nested BBCode code tags like

Issue Forum for Issues suggestions for improvement Forum for Issues obfuscation
This is OK
Issue Forum for Issues suggestions for improvement Forum for Issues obfuscation
:rolleyes:

That will do for this one, I guess I will have to do a recursion wonk to get a version working with nested BB Code Tag code tags,
_.____________-
:rolleyes:
Ok. Here we go:
This code _..
Sub BBCodeCodeTagsWegDaMit2AlanHansPaul2()
_.. is mostly just splicing together codes
Sub WegDaMitHansPaulAlan()
and
Sub LongWayOfDoingIt()
along with adding a short section, Rem 10a) to check that the strings are the same. That is to say the
Full Story selection text from the modified ( removed BB Code code tags ), NewWordText for Code Part 1)
is
compared with the final RapedText from the long string manipulation Code part 2)

The code is all one code and broken down into this and the next three posts

Code part 1 of 4 parts ( all following parts to be copied directly under the preceding part in the same code module.

Sub BBCodeCodeTagsWegDaMit2AlanHansPaul2() ' http://www.excelforum.com/development-testing-forum/1086445-forum-tools-test-no-reply-needed-4.html#post4586680
' === Code assumes you have a Word File open, and have selected some Text
' One way is automating doing it in Word. "Wild Things. You make my heart sing. They make everything….. Groovy" '_- http://www.eileenslounge.com/viewtopic.php?f=26&t=26030#p202322
Rem 0) ' Just mucking about a bit with refering to Word documents
' Documents.Item("eileenslounge.docm").Activate
'Dim DocNme As String ' ' Prepares "Pointer" to a "Blue Print" (or Form, Questionaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular "Value", or ("Values" for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. A String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quich checks.. But..http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring-2.html#post44116
' Let DocNme = ActiveDocument.Name ' ' '_-So A variable in VBA is like the Link to the part of a URL string reducing size site where a few things about the actual Final site is informed about. This area in that site, like a pigion Hole to which the variable refers, ( the "pigeon hole" location address, and all its contents would be defined as the "Pointer". Amongst other things it has a link, a "Pointing part", pointing to actually where all the stuff is
Dim Doc As Document 'A variable in VBA is like the Link to the part of a URL string reducing size site where a few things about the actual Final site is informed about. This area in that site, like a pigion Hole to which the variable refers, ( the "pigeon hole" location address, and all its contents would be defined as the "Pointer". Amongst other things it has a link, a "Pointing part", pointing to actually where all the stuff is
Set Doc = ActiveDocument 'EP Set: Fill or partially Fill: Setting to a Class will involve the use of an extra New at this code line. I will then have an Object referred to as an instance of a Class. At this point I include information on my Pointer Pigeon hole for a distinct distinguishable usage of an Object of the Class. For the case of something such as a Workbook this instancing has already been done, and in addition some values are filled in specific memory locations which are also held as part of the information in the Pigeon Hole Pointer. We will have a different Pointer for each instance. In most excel versions we already have a few instances of Worksheets. Such instances Objects can be further used., - For this a Dim to the class will be necessary, but the New must be omitted at Set. I can assign as many variables that I wish to the same existing instance
Rem Code Part 1) make two temporary Word Files with and without BB Code

DocAElstein
02-20-2017, 05:23 PM
Code part 2 of 4 parts



Rem Code Part 1) make two temporary Word Files with and withouut BB Code
Rem 1) Copy selection to Clipboard
Selection.Copy
Rem 2) Make temporary WORD document 'Bit of a bodge to get the text in a selection: create a Word file and paste to it
Dim NextTempDoc As Document '
Documents.Add: ActiveDocument.Content.Paste 'Make a File Copy in current Application based on Default Type : And Paste from Clipoard ( ...!!!...our original selected text ) using the Default Copy which should at least have all the text, which is all we are interested in here.
Set NextTempDoc = ActiveDocument ' Do this in case i muck about- I do not want to inadvertently close or kill the wrong document
'2b) Copy of Full Text with BB Code
Dim FullFilePathAndFullNameBBCode As String ' 'Prepares "Pointer" to a "Blue Print" (or Form, Questionnaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular “Value”, or (“Values” for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quick checks.. But...http://www.mrexcel.com/forum/excel-q...html#post44116
NextTempDoc.SaveAs FileName:="TempBBCodeCopy1.docx", FileFormat:=wdFormatXMLDocument 'Without this the document will not really "exist jet". It has a tempory name ( Used in Windows referrence ), but no path.
Let FullFilePathAndFullNameBBCode = NextTempDoc.Path & "\" & ActiveDocument.Name
Rem 3) From Han's Text Find Replacement Dialogue 'http://www.eileenslounge.com/viewtopic.php?f=26&t=22603#p175712
'3a) Take out all BB Code
Selection.WholeStory 'Selects whole document which here is just our selection of interest from the original document
Dim StrOrg As String: Let StrOrg = Selection.Text '11a)6b)' Original Text to use in string manipultion code of Code Part 2)
With Selection.Find 'This is the VBA code ( or very similar ) used by Excel when Using the Find eplace text Dialogue box. So this is an improved version of what a macro recording would give.
.ClearFormatting: .Replacement.ClearFormatting ' Don't use formating, ? not sure this comes into the equation ??
.Wrap = wdFindStop ' Tell Word not to continue past the end of the selection ( And therefore prevents also a display Alert asking )
.MatchWildcards = True
.Text = "[\[]([!=\]]@)(*\])(*)\[/(\1)\]" ' 8 sections, 4 identified with ( ) but I only need two ( )
.Replacement.Text = "\3" ' The third of the 4 sections identified with a ( )
.Execute Replace:=wdReplaceAll ' Replace all within selection. This is the "OK" button!
End With
Selection.WholeStory: Dim NewWordText As String: Let NewWordText = Selection.Text '´11a) New text for comparison with result from Code Part 2)
'3b) Copy of Colored Text in Word File without BB Code Code tags
Dim FullFilePathAndFullNameNoBBCode As String
NextTempDoc.SaveAs FileName:="TempNoBBCodeCopy2.docx", FileFormat:=wdFormatXMLDocument 'Without this the document will not really "exist jet". It has a tempory name ( Used in Windows referrence ), but no path.
Let FullFilePathAndFullNameNoBBCode = NextTempDoc.Path & "\" & ActiveDocument.Name
Rem 4) "Reset the "Find Replace Text Dialogue" "Thing" ". if you do not there may be some changed setting there that could catch you out next time you use it.
NextTempDoc.Select ' Re select the...( actually this line alone seems to do it )
Selection.WholeStory '...whole document
With Selection.Find
.ClearFormatting: .Replacement.ClearFormatting: .Text = "": .Replacement.Text = "": .Forward = True: .Wrap = wdFindAsk: .Format = False: .MatchCase = False: .MatchWholeWord = False: .MatchKashida = False: .MatchDiacritics = False: .MatchAlefHamza = False: .MatchControl = False: .MatchWildcards = False: .MatchSoundsLike = False: .MatchAllWordForms = False '
End With
Rem 5) Optiion to close / kill document
NextTempDoc.Close (wdDoNotSaveChanges) ' Giving the option will also prevent being asked for it. You must close. VBA will not let you kill an open sheet, as you are affectively working on a copy, and VBA is assumng the Original can be got at by saving for example. http://www.mrexcel.com/forum/excel-questions/920451-excel-macro-files.html#post4425428
'Kill FullFilePathAndFullNameBBCode ' Use the Kill wisely!!!! - where this goes there 'aint no coming back!!
'Kill FullFilePathAndFullNameNoBBCode

Rem Code Part 2 Put text without BB code into clipboard
Rem 6) Use data Object ( assumes we copied to the Clipboard )
'1 a) Data Object to get the data from the clipboard.
'_- ExPlanation Dim :'_-: For Object variabls: Address location to a "pointer". That has all the actual memory locations (addresses) of the various property values , and it holds all the instructions what / how to change them , should that be wanted later. That helped explain what occurs when passing an Object to a Call ed Fucntion or Sub Routine By Val ue. In such an occurance, VBA actually passes a copy of the pointer. So that has the effect of when you change things like properties on the local variable , then the changes are reflected in changes in the original object. (The copy pointer instructs how to change those values, at the actual address held in that pointer). That would normally be the sort of thing you would expect from passing by Ref erence. But as that copy pointer "dies" after the called routine ends, then any changes to the Addresses of the Object Properties in the local variable will not be reflected in the original pointer. So you cannot actually change the pointer.)
'_- Explanation Set :'_-: Fill or partially Fill: Setting to a Class will involve the use of an extra New at this code line. I will then have an Object referred to as an instance of a Class. At this point I include information on my Pointer Pigeon hole for a distinct distinguishable usage of an Object of the Class. For the case of something such as a Workbook this instancing has already been done, and in addition some values are filled in specific memory locations which are also held as part of the information in the Pigeon Hole Pointer. We will have a different Pointer for each instance. In most excel versions we already have a few instances of Worksheets. Such instances Objects can be further used., - For this a Dim to the class will be necessary, but the New must be omitted at Set. I can assign as many variables that I wish to the same existing instance
'Dim objCliTextCopied As DataObject '**Early Binding. This is for an Object from the class MS Forms. This will be a Data Object of what we "send" to the Clipboard. So I name it CLIpboardSend. But it is a DataObject. It has the Methods I need to send text to the Clipboard
' Set objCliTextCopied = New DataObject '**Must enable Forms Library: In VB Editor do this: Tools -- References - scroll down to Microsoft Forms 2.0 Object Library -- put checkmark in. Note if you cannot find it try OR IF NOT THERE..you can add that manually: VBA Editor -- Tools -- References -- Browse -- and find FM20.DLL file under C:\WINDOWS\system32 and select it --> Open --> OK. http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/
' ( or instead of those two lines Dim obj As New DataObject ). or next two lines are.....Late Binding equivalent'
Dim objCliTextCopied As Object ' Late Binding equivalent' If you declare a variable as Object, you are late binding it. http://excelmatters.com/2013/09/23/vba-references-and-early-binding-vs-late-binding/
Set objCliTextCopied = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") ' http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/
'6a) Original text string from '11a) The line below means I have nothing to do with the Clipboard yet' - see furhter to the right for .Geting From Clipboard for if it had been in it ' 'Put all? Clipboard Infomation into Data Object
objCliTextCopied.SetText Text:=StrOrg ' I am messing about putting this in data object, then taking it out on 6b) , but I just wanted the code to be more flexible for later use. ' ''objCliTextCopied.GetFromClipboard 'All that is in the Clipboard goes in this Data Object initial instance of the Class This line does not seem to be necerssary for the next Geting Text bit

DocAElstein
02-20-2017, 05:24 PM
Code Part 3 of 4 parts


'6b) get code as long string String. This can be very long
Dim TextWithBBCodeEnit As String ' 'Prepares "Pointer" to a "Blue Print" (or Form, Questionnaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular “Value”, or (“Values” for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quick checks.. But...http://www.mrexcel.com/forum/excel-q...html#post44116
Let TextWithBBCodeEnit = objCliTextCopied.GetText() ''retrieve the text in this instance of the Class. ( Our code as a String with probably BB Code Code tags, vbCr vbLf etc.
Rem 7) Determine length of original text
Dim LenText As Long ' ' Long is very simple to handle, - final memory "size" type is known (123.456 and 000.001 have same "size" computer memory ) , and so a Address suggestion can be given for the next line when the variable is filled in. '( Long is a Big whole Number limit (-2,147,483,648 to 2,147,483,647) If you need some sort of validation the value should only be within the range of a Byte/Integer otherwise there's no point using anything but Long.--upon/after 32-bit, Integers (Short) need converted internally anyways, so a Long is actually faster. )
Let LenText = Len(TextWithBBCodeEnit)
MsgBox prompt:="Text with BB Code Character count is " & LenText
Rem 8) Take out BB Code bits from text string.
40 Dim strRmveBBCode As String: Let strRmveBBCode = TextWithBBCodeEnit ' = strBBCode ' This will be adjusted until finally has no BBCode tag pairs
50 Dim Lstr As Long ' This will be adjusted as necerssary for current length ' Long is very simple to handle, - final memory "size" type is known (123.456 and 000.001 have same "size" computer memory ) , and so a Address suggestion can be given for the next line when the variable is filled in. '( Long is a Big whole Number limit (-2,147,483,648 to 2,147,483,647) If you need some sort of validation the value should only be within the range of a Byte/Integer otherwise there's no point using anything but Long.--upon/after 32-bit, Integers (Short) need converted internally anyways, so a Long is actually faster. )
60 Let Lstr = Len(TextWithBBCodeEnit) ' Len(strBBCode)
70 Rem 2) Loop through and get a BB Code section
80 Dim strBBCodePair As String ' for a found valid pair '
' Prepares "Pointer" to a "Blue Print" (or Form, Questionaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular “Value”, or (“Values” for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. A String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quich checks.. But..http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring-2.html#post44116
90 Dim posCurrent As Long 'Current position in the string' Loop Bound variable Count '_-Main Loop==========================
100 For posCurrent = Lstr To 2 Step -1 'Important to go backwards as we chop off behind us so have a less complicated current position. We look at pos-1 in some code parts so we would error if we went back to less than 2
110 '2a) Check for a ]
120 If Mid(strRmveBBCode, posCurrent, 1) = "]" Then
130 Dim posBBCodeTagSrch As Long 'For search through possible valid BBCode Section'_-Loop for Pos tag pair section--
140 Dim BcrdEEnd As Long: Let BcrdEEnd = posCurrent 'Position of possible End Code Tag End
150 For posBBCodeTagSrch = posCurrent - 1 To 2 Step -1 'PosCurrent is set here at loop start. ###It is not effected by cardinally sining changing PosCurrent Loop Bound variable caount in Outer main Loop
160 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "]" Then GoTo NxtCESPosPos ' If we hit another ] then start again to see if is a valid BB code section
170 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "/" And Mid(strRmveBBCode, posBBCodeTagSrch - 1, 1) = "[" Then 'We hit start of a BB Code end tag
180 Dim BcrdESt As Long: Let BcrdESt = posBBCodeTagSrch - 1 'Position of End Code Tag Start
190 Exit For ' We leave this For the End Code Tag Start Search, Exit For with a [ at posBBCodeTagSrch-1
200 Else 'Not found start of end Tag or stop of end Tag.
210 End If
220 NxtCESPosPos: Next posBBCodeTagSrch ' go back in possible BB code string
230 If posBBCodeTagSrch = 3 Then Exit Sub 'case we never found the start of an End Code Tag
240 For posBBCodeTagSrch = posBBCodeTagSrch - 2 To 2 Step -1 ' Once again ### the start is set and fixed, the Loop Bound Variable Count will change
250 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "]" Then
260 If Mid(strRmveBBCode, posBBCodeTagSrch - 1, 1) = "]" Then GoTo NxtCSSPosPos ' If we hit another ] then start again to see if is a valid BB code start section
270 Dim BcrdSEnd As Long: Let BcrdSEnd = posBBCodeTagSrch 'Position of possible Start Code Tag End
280 Dim LTagStLoop As Long 'Last loop to find start of start Code Tag
290 For LTagStLoop = posBBCodeTagSrch - 1 To 1 Step -1 '_- Second inner loop___________________________
300 If Mid(strRmveBBCode, LTagStLoop, 1) = "[" Then
310 Dim BcrdSSt As Long 'Have to put it here, - I may occaisionally have to set it to 0 in next line
320 If Mid(strRmveBBCode, LTagStLoop + 1, 1) = "/" Then Let BcrdEEnd = BcrdSEnd: Let BcrdSEnd = 0: Let BcrdESt = LTagStLoop: Let BcrdSSt = 0: Let posBBCodeTagSrch = LTagStLoop: GoTo NxtCSSPosPos ' Found a second end Code Tag. So change the previous found start and stop , and adjust the Loop Bound variable Count appropriately for a new search for a start Code Tag
330 Let BcrdSSt = LTagStLoop
340 Let posCurrent = BcrdSSt 'End of Code Tag section search
350 GoTo FkOffCrd ' We leave this For the start Code Tag Start Search and go to Fuk Off Crd:
360 Else ' Still looking for start of start Code Tag
370 End If
380 Next LTagStLoop '_- Second inner loop______________________________________________ __________________
390 If LTagStLoop = 1 Then GoTo TheEnd 'Case we found a start start [ at 1 or failed to find a start start [ for the complete possible Code Tag section search
400 Else 'Not found end of start Tag or start of start Tag
410 End If
420 NxtCSSPosPos: Next posBBCodeTagSrch ' go back in possible BB code string'_-Loop for Pos tag pair section-----------------

DocAElstein
02-20-2017, 05:24 PM
Code part 4 of 4 parts




430 FkOffCrd: Rem 3) "I think we come here with a complete set of 4 positions"
440 If BcrdEEnd <> 0 And BcrdESt <> 0 And BcrdSEnd <> 0 And BcrdSSt <> 0 Then 'Just to check'
450 Dim SttBcrd As String, StpBcrd As String ' Start and stop tags
460 Let SttBcrd = Mid(strRmveBBCode, BcrdSSt, BcrdSEnd - BcrdSSt + 1): Let StpBcrd = Mid(strRmveBBCode, BcrdESt, BcrdEEnd - BcrdESt + 1)
470 Dim SttWrd As String, StpWrd As String ' like |Color=Red|, |/Color|
480 Let StpWrd = Mid(StpBcrd, 3, Len(StpBcrd) - 3) ' like Color from |/Color| - Whole Word, from 3rd Chr , for Length as WholeWord-3
490 Let SttWrd = Mid(SttBcrd, 2, Len(StpWrd)) ' like Color from |Color=Red|
500 If UCase(SttWrd) = UCase(StpWrd) And Mid(StpBcrd, 2, 1) = "/" Then 'Ucase allows for differences in cases And Mid(SttBcrd, Len(SttWrd) + 2, 1) = "=" Then
510 Let strRmveBBCode = Replace(strRmveBBCode, SttBcrd, "", 1, 1) ' Replace in ( strRmveBBCode , the start tag , with no string , start loooking from and return from character 1 )
515 Let strRmveBBCode = Replace(strRmveBBCode, StpBcrd, "", 1, 1)
520 Else 'No shortening of string foe invalid tag word
530 End If
540 Else ' no last ] of a possible Code section yet, so keep going back down in the main string
550 End If
560 Else
570 End If
580 Next posCurrent '_-===Main Loop============================================== ==========================================
'590 TheEnd:
600 MsgBox prompt:="" & strRmveBBCode & "": Debug.Print "" & strRmveBBCode & "" 'Hit Ctrl+g when in VB Editor Window, reveal Immediate window after code run
Dim RapedText As String: Let RapedText = strRmveBBCode ' TextWithBBCodeEnit with BB Code Code tags removed
Rem 9) This a Another Object from class to be sure we have the data in the Clipboard
'Dim objDat As DataObject
'Set objDat = New DataObject 'Set to a new Instance ( Blue Print ) of dataobject
Dim objDat As Object
Set objDat = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
'9b) Put in (and Get back from clipboard) the raped text.
objDat.SetText Text:=RapedText 'Make Data object's text equal to original text without the BB Code Code Tags
objDat.PutInClipboard 'Place current Data object into the Clipboard
objDat.GetFromClipboard 'All that is in the Clipboard goes in this Data Object second instance of the Class.
Dim TxtOut As String: Let TxtOut = objDat.GetText() 'retrieve the text in this second instance of the Class. ( In this case all in it is the text and possibly vbCr and vbLf )
MsgBox prompt:="You dumped in Clipboard this " & vbCr & RapedText & vbCr & "and if you try to get it, you should get" & vbCr & TxtOut & ""
Rem 10a) Code Part 3) Belt and braces check. A check is then done finally to see if the two raped from tags strings are the same
If NewWordText <> RapedText Then MsgBox prompt:="Text from Word Dialogue Box Find Replace Wild card way, and " & vbCrLf & "Long String manipulation way are not the same. Oh dear"
'10b) Tidy up.
TheEnd: ' ( Come here always, even on a unpredictable error ) or i wouod If i had an error Handler, Lol.
Set objDat = Nothing ' Good practice... maybe....
Set objCliTextCopied = Nothing ' ....... http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring.html#post4414065

End Sub

DocAElstein
02-24-2017, 08:57 PM
One problem noted in the previous codes was that the case of nested BB Code tag pairs, the codes did not work. At many forums such nesting of this form is permitted in BB codes.
Comments Highlight Comments
The returned result is
Comments Highlight Comments

None of the codes discussed so far will work for such a case.
Should the Code tag type be dissimilar, such as_..

Title
_..then at least the Find Replace Wildcard Code will work for that by virtue of matching in the String first, for example, in the above example, _..
__ CENTER __ __ __ __ CENTER __
_.. then
__ B __ __ __ __ B __
However my Long string manipulation code will not even work for that.

I have done a Long string manipulation code to be discussed in this and the following posts which , I think, work for all situations.

Brief Descriptions is:
The entire string is held in a variable, strBBCode. This is declared in a Subroutine. Something similar to that was done for the last code )

change 1) Minor to last code:
Unlike the previous codes, ( which sequentially removed BB Code code tags ( by replacing with "" )), the code tags are replaced by some arbitrary character ( This is simply chosen as any not likely to be used as text in the main initial string https://www.mrexcel.com/forum/excel-questions/867942-visual-basic-applications-new-1-d-array-selected-index-2-d-array-2.html#post4214083 )

change 2) Minor
This itself is not such a major change in the code format, but it facilitates the main change, 3) below. This change is that bulk of the code is within a Function, (Function LongWayOfDoingIt2ReCurseCyClops(__ ) . It is “Called” and needs to be given_..
_.. the string, strBBCode, By Referral to that variable, rather than its By its Value contents
and_..
_.. a Value for the current character position, which initially will be the end ( or length in characters ) position of strBBCode.

But those are not the main changed characteristic to the code.
To recap: All my long string manipulation codes, including this Function, have the general characteristic that they loop backwards in the complete string until a ] is found. An attempt is made then to find a [/ . Once this is found an attempt is made to find a ] and then a [ .
At this point a possible code pair requirement , looking backwards, of ] [/ ] [ is achieved
( Reversing that to the correct order shows that clearly more clearly,
[ _ ] __ [/ _ ],
or
AnyText .
Or
AnyText
_.. etc...)
Having found a code tag pair, a check is made for its validity ( the same matching work, such as, codetext, color, for example ) , before the adjustments are made to the main string. After that , the code then moves on and steps further “back” in search of another pair_..
_.. But just before it does that check, all codes, including this new Function, at the last found [ , do a check to see if in fact the next character after the last found [ is a / , indicating that in fact the assumed start tag, [codeText], was in fact another end tag, [/Codetext_b]. Action is then taken should that be the case.
At this point the codes are very different. The action taken is different
In the previous code, it was assumed that in such an event, the first found “end tag” was a rouge text looking like an end tag , but invalid, and not matched to a start code tag. The first found “end tag” was then ignored, and another search made for a matching start tag to the second found end tag.
This results in an error situation for a valid nested BB Code tags situations.
The new code works therefore much differently.

Main change 3):
In the new code, this point is around lines
430 – 460, Rem If [/ Then Oh dear time for a wonk.
Recursion is the name given for the general technique which at this point is used. It is whereby within a routine an instruction is given to run the routine.
:rolleyes: ... In other words the Routine “Calls itself”.
So what is all that about? :
‘_- I will tell you, Matey boy:
Any Function or Sub routine we write, is just a set of instructions. Like a piece of paper which is a Print out of the typed code instructions. It tells VBA what to do when it is run or called. I does not really physically go along or through the code lines: We just find that easy to visualise, or “look at “ when “stepping” through to debug a code. The code is just a set of instructions that VBA understands.
So imagine you are VBA and you are given a set of instructions ( on a piece of paper ) to do a job, (for example you are given a written copy of the instructions to read and follow).
You start doing the instructions.
Now, say, before you are finished, you are given a set of identical instructions and are told to do that by the boss. What do you do, ( apart from swear at him ) ?
The logical progression is, ( and that is what VBA does ), it stops what it is doing, so like freezes the initial running through the instructions , and starts again with the new ( duplicate as it happens in the case of “recursion”) set of instructions.
Once finished it goes back and picks up the first job where you / it left off. Within reason, there is no limit to how often you can do that in VBA. If a code makes a Function or Sub routine keep “Calling” itself , then it “stacks” up in order in a “waiting list” the stopped set of instructions. As each set of instructions is completed, the last are continued at the point where they were interrupted and “frozen”. That point is code line 450
It follows, ( although may not be immediate obvious as the same names are used) that all variables used in each run of the Function within the function are unique to that run of the function so do not influence the values of the similarly named variables in the other Function runs. An exception here is our main full string, strBBCode. This is because we have deliberately chosen to carry it over By such a way as to indicate it should be Referenced to within each Function. So in this case, changes made in any Function run to strBBCode will be Reflected in the main ( unique ) variable, strBBCode, which is initially “held” / declared in the initial calling code.
So what is all that to do with the main change to this code version ??
‘_- I will tell you, Matey boy:
Initially the Function is called the first time by a small Sub routine which passes to the Function two things
_(i) the variable strBBCode. It is indicated via the use of ByRef in the Function signature ( first ) line, that specifically that variable is to be Referenced. ( You may effectively take a variable “into” the Function ( ByRef ) , or alternatively a Value. If an actual value is given, then giving it ByRef is just the same as By Value. If you pass a Variable ByValue the value at the time of the Call in the variable will be taken, and that variable will become local to the Function and so any changes to it made in the function will not be reflected in the variable “held” in the initial calling routine ........ )
_...(ii) a number .......Value... is given which will be the start position to work back from when looping backwards through the characters in strBBCode. For this first Call, that will be the length of / or character count of , strBBCode.

The Function code then transgresses as described and very similar to the previous code. It can go to completion in one run should no end code tag be encountered after an initial one is found and before a start tag is found.
____If a second end tag in sequence is found the "recursion wonk" kicks in.....
450 _____ Call LongWayOfDoingIt2ReCurseCyClops(strBBCode, BcrdSEnd)
So _ If this line is done, the current run freezes. A New Function begins. This is instructed to Refer to the unique main string strBBCode “held” in the original Calling routine. As Value for the current position in the backward stepping search is this time not the main string strBBCode length, but rather the position of the end ] in the currently found second sequential end code tag.
The only thing that is certain at this point is that the new Function run will immediately find this second end cote tag as its first end code tag. This is probably inefficient as it repeats some steps done. ( A more complicated Function could be envisaged to carry across an Offset to be applied to “jump” this search and pass the end code tag )
With no more nested code tag pairs, the second Function will complete the entire string, other than the possible code tag pair search “frozen” in the first Function.
When the first function resumes, the initial code tag pair search is completed.

There are many other scenarios including a further nested code tags section the second function finds and results in a third Function starting. That third Function would complete all but the two pairs searches “frozen” . At completion of the third Function, the second and then the first Functions with their respective code tag pair search would be completed.

Another scenario would be a double nesting such that there are three sequential end code tags. Once again a second followed by a third Function would be started. Once again, the third Function would complete all but the two pairs searches “frozen”. At completion of the third Function, the second and then the first Functions with their respective code tag pair search would be completed.

One can imaging many more scenarios

One common factor is that all but the final function will be searching through the replaced replacement characters. This probably makes the code a bit inefficient

Final usage of Function
Initial code to Call the Function for the first time. ( The function may Call itself one or more times further )
The Function will not run itself.
It needs to be Called with the initial parameters passed, the main string, strBBCode, along initially with the length of that string as the start point from which to step back.
A routine is needed for that.
Additionally, once the initial Function run , ( which is set off by this routine ) is finished, we will have the original string, strBBCode , returned in a modified form with the replacement character in place of all found code tags. These need to be removed, which can be easily achieved by replacing them with zero length strings.
An example code is given in the next post.

A few minor last thoughts..
This second solution for manipulating a long string text does not require stepping backwards. It was simply developed on from the last code. That code was easier to do backwards as in the code parts were deleted whilst stepping through the string: It was easier to deal with such a code in a backward loop, as things “behind me” are deleted. The problem with going forward is that “deleting in front of me” can require adjusting “where I am”, and the count to, or “final point of where I am going to”. – Think of it as you tripping up, or effecting where the end is, if you chop out the path in front of you: VBA can get messed up in Looping if you remove points in a progression that have not yet been considered.
Another way of thinking about that:
If I take bits out, then things shift back or down to fill the space. If I take things out in front of me, then by shifting back, things which I have not yet considered will change their position. This will likely mess up some order of progression.
If I go backwards, and delete things behind me, then any order changes will only affect things which I have already considered. My original progression plan and order of things not yet considered is still valid.

DocAElstein
02-24-2017, 08:58 PM
Final usage of Function
Initial code to Call the Function for the first time. ( The function may Call itself one or more times further )
The Function in the next Post will not run itself.
It needs to be Called with the initial arguments , ( __ ( strBBCode, BkStt) __ ), passed, the main string, strBBCode, along initially with the length of that string as the start point from which to step back, BkStt
A routine is needed for that.
Additionally, once the initial Function run , ( which is set off by this routine ) is finished, we will have the original string, strBBCode , returned in a modified form with the replacement character in place of all found code tags. These need to be removed, which can be easily achieved by replacing them with zero length strings.




Example Code:

'10 '
Sub TestsBBCodeString() '
20 '
30 Rem 2 Bits needed as Part of Solution
40 '2a) String will need to be got. The variable for it is referred to by changes in any Functions used. The initial length is effectively just the current position stepping back through the total character string
50 ' Some variables: So A variable in VBA is like the Link to the part of proxy site where a few things about the actual Final site is informed about. Tiny is the pointer. Amongst other things it has a link to actually where all the stuff is. Like Dim Str As String means at Str will be stuff like how long the text in that string is as well as a link to the memory where the whole string actually is. So that is like more efficient if you want to get at the length – you do not need to go off to where the ( possibly massive ) thing is.. etc.. :-)
60 Dim strBBCode As String ' ' Prepares "Pointer" to a "Blue Print" (or Form, Questionaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular “Value”, or (“Values” for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. A String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quich checks.. But..http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring-2.html#post44116
70 Let strBBCode = "gggg245[/8]x[dddAny text" ' Any test string, this code part takes the place of a code section that might for example get the text that may hve been copied to the Clipboard
80 Dim Lenf As Long ' ' Long is very simple to handle, - final memory "size" type is known (123.456 and 000.001 have same "size" computer memory ) , and so a Address suggestion can be given for the next line when the variable is filled in. '( Long is a Big whole Number limit (-2,147,483,648 to 2,147,483,647) If you need some sort of validation the value should only be within the range of a Byte/Integer otherwise there's no point using anything but Long.--upon/after 32-bit, Integers (Short) need converted internally anyways, so a Long is actually faster. )
90 Let Lenf = Len(strBBCode)
100 '2b) Calling the Function (So a Sub would do also-as the Sub has arguments it would like any function not be shown in Macro list. The point of a ByRef call is to effectively return a value, a change to a value actually )
110 Call LongWayOfDoingIt2ReCurseCyClops(strBBCode, Lenf) ' This replaces the code tag characters to be removed with some arbritrary characters.
120 '2c) The arbritrary charachters need to be removed
130 Let strBBCode = Replace(strBBCode, "|", "", 1, -1) ' within strBBCode , "|" , replaced with "" , -1 indicating all of them
End Sub






The Function to be called_..
Public Function LongWayOfDoingIt2ReCurseCyClops(ByRef strBBCode As String, ByVal BkStt As Long) As String
_.. is given in the next post.

https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg (https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg)
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgzMCQUIQgrbec400jl4AaABAg (https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgzMCQUIQgrbec400jl4AaABAg)
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgwhVTFaD469mW9wO194AaABAg.9gJzxwFcnPU9gORqKw5t W_ (https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgwhVTFaD469mW9wO194AaABAg.9gJzxwFcnPU9gORqKw5t W_)
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugyb8nmKKoXvcdM58gV4AaABAg (https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugyb8nmKKoXvcdM58gV4AaABAg)
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgwvvXcl1oa79xS7BAV4AaABAg (https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgwvvXcl1oa79xS7BAV4AaABAg)
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgxvIFArksPprylHXYZ4AaABAg (https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgxvIFArksPprylHXYZ4AaABAg)
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg (https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg)
https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxUbeYSvsBH2Gianox4AaABAg.9VYH-07VTyW9gJV5fDAZNe (https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxUbeYSvsBH2Gianox4AaABAg.9VYH-07VTyW9gJV5fDAZNe)
https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxLtKj969oiIu7zNb94AaABAg (https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxLtKj969oiIu7zNb94AaABAg)
https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgyhQ73u0C3V4bEPhYB4AaABAg (https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgyhQ73u0C3V4bEPhYB4AaABAg)
https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgzIElpI5OFExnUyrk14AaABAg.9fsvd9zwZii9gMUka-NbIZ (https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgzIElpI5OFExnUyrk14AaABAg.9fsvd9zwZii9gMUka-NbIZ)
https://www.youtube.com/watch?v=jdPeMPT98QU (https://www.youtube.com/watch?v=jdPeMPT98QU)
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

DocAElstein
02-27-2017, 01:58 AM
Recursion Function to remove BB Code code tags, described in last two posts



'140 '
Public Function LongWayOfDoingIt2ReCurseCyClops(ByRef strBBCode As String, ByVal BkStt As Long) As String ' I do not actually need any As ______ as nothing is returned, but you never know a string to retuen might be useful later
150 Dim vTemp As Variant ' For Debugs
160 '
170 Rem 1) Main Loop for finding BB code pair String=====================================
180 Dim StpBk As Long
190 For StpBk = BkStt To 1 Step -1 ' Looking for the first ] likely at end of end tag.
200 Let vTemp = Mid(strBBCode, StpBk, 1)
210 If Mid(strBBCode, StpBk, 1) = "]" Then ' we note Position and need to look for a [/ On a recursion call this conditiuon is always met
220 Dim BcrdEEnd As Long: Let BcrdEEnd = StpBk ' Position of possible End Code Tag End
230 Dim posBBCodeTagSrch As Long ' For search through possible valid BBCode Section'_-Loop for Pos tag pair section--
240 For posBBCodeTagSrch = StpBk To 2 Step -1
250 If Mid(strBBCode, posBBCodeTagSrch, 1) = "]" Then Let BcrdEEnd = posBBCodeTagSrch: GoTo NxtCESPosPos ' If we hit another ] then change the stop tag stop character position and start again to see if is a valid BB code section
260 If Mid(strBBCode, posBBCodeTagSrch, 2) = "[/" Then ' Found a stop tag "[/" at posBBCodeTagSrch, so mark..
270 Dim BcrdESt As Long: Let BcrdESt = posBBCodeTagSrch ' ..Position of End Code Tag Start and ..
280 Exit For ' we have an end code tag from a possibly code tag pair section
290 Else 'No luck finding a "[/" start bit of stop tag yet so keep looking Matey
300 End If
310 NxtCESPosPos: Next posBBCodeTagSrch ' trying to find a start [/ pair further back keep looking Matey
320 If posBBCodeTagSrch = 3 Then Exit Function 'case we never found the start of an End Code Tag
330 ' Loop likely at end of start tag ]
340 For posBBCodeTagSrch = BcrdESt - 1 To 1 Step -1 ' Looping furhter back to find a "]" likely of a start code tag but possibly a nested stop tag
350 If Mid(strBBCode, posBBCodeTagSrch, 1) = "]" Then ' possible start from back of "]" likely of a start code tag but possibly a nested stop tag found so....
360 If Mid(strBBCode, posBBCodeTagSrch - 1, 1) = "]" Then GoTo NxtCSSPosPos ' we have a second "]" one back, looking back so this will be caught by next back 1
370 Dim BcrdSEnd As Long: Let BcrdSEnd = posBBCodeTagSrch ' Position of possible Start Code Tag End
380 Dim LTagStLoop As Long ' _- Most Innerloop to find start of start Code Tag
390 For LTagStLoop = posBBCodeTagSrch - 1 To 1 Step -1 ' _- Most inner loop [ likely start of start tag_
400 If Mid(strBBCode, LTagStLoop, 1) = "[" Then
410 Dim BcrdSSt: Let BcrdSSt = LTagStLoop
420 Rem If [/ Then Oh dear time for a "recursion wonk"
430 If Mid(strBBCode, LTagStLoop, 2) = "[/" Then 'Seems like our last attempt at finding a start tag caught a nested end tag
440 'Time to freeze this Function with current end tag info.
450 Call LongWayOfDoingIt2ReCurseCyClops(strBBCode, BcrdSEnd) ' Position of possible Start Code Tag End is actually another end tag end, so give this ] position as the start position and run another copy of the Function. At the start of which the first check should catch the ] and redo the finf´ding of the last tag complete so is a bit ineffecient
460 'Time to unfreeze this Function, and continue where left off having now possibly modified the main string for one or more nested tag pairs, as well as probably catching all but the possible pair that I froze on
470 Let posBBCodeTagSrch = LTagStLoop ' When we went off to the copy of the function our LTagStLoop was at the start of what turned out to be a nested end code tag. That is as good a place as any to strt going further back now to try to find the match for the end tag before the nested one. We will be going throught the lkast nested one, but never mind
480 GoTo NxtCSSPosPos ' unfreeze search for a matching start tag
490 Else ' As soon as we come here we are likely
500 End If ' ready to do the string modification for a found matching pair
510 Let StpBk = BcrdSSt ' - 1 will be done at Next StpBk 'End of Code Tag section search ' I am commiting the cardinal sin of changing the Loop bound variable caount in the main outer step back in character Loop
520 GoTo FkOffCrd ' We leave this For the start Code Tag Start Search and go to Fuk Off Crd:
530 Else
540 End If
550 Next LTagStLoop ' _- End Most inner loop [ likely start of start tag_
560 If LTagStLoop = 1 Then GoTo TheEnd 'I think here we must always be at LTagStLoop = 1 - Case I think we failed to find a start start [ for the complete possible Code Tag section search
570 Else ' Not found a "]" likely of a start code tag but possibly a nested stop tag found
580 End If
590 NxtCSSPosPos: Next posBBCodeTagSrch ' End Loop likely end of start tag ]
600 If posBBCodeTagSrch = 0 Then GoTo TheEnd ' For any outer search failed to find a ] at all or a search for matching start tag that was fruitless
610 FkOffCrd: Rem 3) "I think we come here with a complete set of 4 positions"
620 If BcrdEEnd <> 0 And BcrdESt <> 0 And BcrdSEnd <> 0 And BcrdSSt <> 0 Then 'Just to check'
630 Dim SttBcrd As String, StpBcrd As String ' Start and stop tags as complete strings including [ and ]
640 Dim LenSttBcrd As Long, LenStpBcrd As Long ' Some extra variables for clarity
650 Let LenSttBcrd = BcrdSEnd - BcrdSSt + 1: Let LenStpBcrd = BcrdEEnd - BcrdESt + 1 ' As taypical to get length of anything when start and stop positions are known.. -- (stoppos-startpos+1)
660 Let SttBcrd = Mid(strBBCode, BcrdSSt, LenSttBcrd) ' In String , part from [ , for length (stoppos-startpos+1) ' like |Color=Red| or |b|
670 Let StpBcrd = Mid(strBBCode, BcrdESt, LenStpBcrd) ' like |/Color| |/b|
680 Dim SttWrd As String, StpWrd As String
690 Let StpWrd = Mid(StpBcrd, 3, Len(StpBcrd) - 3) ' like Color from |/Color| - Whole Word, from 3rd Chr , for Length as WholeWord-3
700 Let SttWrd = Mid(SttBcrd, 2, Len(StpWrd)) ' like Color from |Color=Red|
710 If StrComp(StpWrd, SttWrd, vbTextCompare) = 0 And Mid(StpBcrd, 2, 1) = "/" Then ' If UCase(SttWrd) = UCase(StpWrd) And Mid(StpBcrd, 2, 1) = "/" Then 'Ucase allows for differences in cases
720 Mid(strBBCode, BcrdSSt, LenSttBcrd) = String(LenSttBcrd, "|") ' Mid can be used to put in strBBCode , starting from start of tag , for a length space within of the tag = any symbol as many times as that length space
730 Mid(strBBCode, BcrdESt, LenStpBcrd) = String(LenStpBcrd, "|")
740 Else ' ' No manipulationn of string for non matching tag word
750 End If
760 Else 'No manipulation of string for not all 4 [ and ] found. Not sure if I ever come here..
770 End If
780 Else ' Case no "]" found in main strBBCode
790 End If
800 Next StpBk ' Stepping further back in Main Loop for finding first "]"============
810 TheEnd:
820 ' Let LongWayOfDoingIt2ReCurseCyClops = "Return from Function after running" ' Option if I wanted to give a value to be returned from Function. By virtue of the ByRef at signature line I effectively continually apply changes to the variable strBBCode
End Function

DocAElstein
03-01-2017, 09:14 PM
The next few posts are intended to share a few codes and ideas and explanations thereof for the some codes to manipulate text including BB Code Code Tags. The codes will consider text in a WORD document, or simple text copied from anywhere into the Clipboard.
One use of this would be that this prepared text could then be copied across to a Forum Editor before posting the Reply. This has been getting more popular recently.
Most people do not actually favor longer posts and prefer using the Forum Editor for a quick monochrome response. A minority have asked me to share the codes and stuff I use when preparing longer posts in Word. So will post here and refer here when I am asked. I don’t think it suits a “Tips and Tutorials “ post in this case



BB Code What is that.
You need to understand the basic idea about code of the HTM, HTML type . All you need to understand is the typical form , pseudo, like with a “start” and a “stop” so that the actual stored “source” file might look like this ( stored usually in plain black and white – I am just using color to help show up different bits )

_____|MakeColor=Red|I want this to be red|/MakeColor|

So that above would be stored in a simple text File with a name like “MyBBCodeText.txt”. It would just be monochrome ( Black and white) text.

In general , the purpose of such a code is to produce somehow in some way this, for you to “see”

_____I want this to be red

It is code of that basic sort that comes down the internet lines to you. Your Browser is like the program that translates that to what you want to see.

In Forum Software from a company or companies that go by the name of Bulletin or similar, they use a simplified version of this sort of code. The text of anything that you post is actually held in such a simple .txt type Text File.

If you wish to, you can actually write using the BB Code format in any reply window. What is then actually displayed in the final seen Thread, is what is interoperated by the Forum software: The Forum Software will recognize simple text and / or BB Code.

For example , If you type the following two BB Code lines in the Forum Editor Window:_..
( Note:For a “CODE tag pair” you have a short cut Icon # ( Not available at Eileen’s Lounge ) )_......

I want this to be red


This I want to come out in Code Tags


So it should look like this in the Forum Editor Window
CodeTags.jpg http://imgur.com/xmSkc4O 502044
18961896




_....... then you will get this in the posted “seen” reply
CodeTagsPosted.jpg http://imgur.com/TeUUj02
5020461897
1897


It is well worth logging in to the Forum, then going into the Test Area_..
http://www.excelforum.com/development-testing-forum/
http://www.eileenslounge.com/viewforum.php?f=4
_.., then start a Thread with a title such as “just testing - No reply needed”
Experiment with BB Codes, especially the BB code CODE Tags. You should always use code tags for code: See rule 3.
English: http://www.excelforum.com/forum-rules/642590-forum-rules.html
Other languages: http://www.excelforum.com/forums-rules/

Here some of the available BB Codes:
http://services.runescape.com/m=forum/forums.ws?278,279,877,64690220
http://www.excelforum.com/misc.php?do=bbcode
For Eileen's Lounge there are some differing characterisics.
http://www.eileenslounge.com/viewtopic.php?f=50&t=108



Note the Forum editor “Eats” spaces of greater than one in normal text. So if you type this in a Forum Editor:_..
My________Text_______with_______Spaces
_.. then after posting, what you “see” will be this:
My Text with Spaces.

There two ways to overcome this problem:
_1) Use the “white character trick”, using the color white: Type this in the Forum editor:
My________Text_______with_______Spaces
On posting you will see this:
My________Text_______with_______Spaces
If you look very carefully you may see this:
My________Text_______with_______Spaces
What you are doing with the “white character trick” is simply displaying white text on a white background.

_2) Code tags preserve spaces. So post your text in the Forum Editor Window in Code tags thus:

My________Text_______with_______Spaces

This will then come out thus:

My Text with Spaces

Note , Use of the Code tags can be very useful to compress , or make tidy, long text extending to the right. – The text can be effectively “hidden” to the right, and only viewable by use of the horizontal scroll bar. *1
Similarly, large tables and text can be compressed and only viewable by transgressing with the vertical scroll bar *2








_................................


The next posts discus some extra codes allowing easier manipulation of BB Code in a word document as a further way prepare a Forum Reply. This prepared text could then be copied across to a Forum Editor before posting the Reply. This has been getting more popular recently












'_- Rem ref:
'_- http://www.excelforum.com/the-water-cooler/1103850-extra-space-or-spaces-in-text-in-forum-post-bb-code-for-extra-space.html
'_- https://www.mrexcel.com/forum/about-board/830361-board-wish-list-5.html#post4369692
'_- https://www.mrexcel.com/forum/about-board/780464-re-text-format-forums-o00o-%60-_-%60-o00o.html
'_- *1 https://www.mrexcel.com/forum/about-board/830361-board-wish-list-7.html#post4466491
'_- *1 http://www.excelfox.com/forum/showthread.php/1976-Code-Tag-Test-with-Long-Comments#post9696
'_- http://www.excelfox.com/forum/showthread.php/2041-Editor-Formating-Test
'_- *2 http://www.excelforum.com/development-testing-forum/1161667-messin-round-just-ignore-me.html#post4513357
'_- *2 http://excelmatters.com/excel-forums/#comment-199348
'_- https://www.mrexcel.com/forum/about-board/990573-editing-post-2.html#post4752733

DocAElstein
03-01-2017, 10:08 PM
Sample Codes

The codes in this Word File, I will probably update from time to time, but the Link will probably stay the same:
“eileenslounge.docm”
https://app.box.com/s/mtwz5jil0p5nbymqrb1cgszjuyg94bea
I actually transfer all my current macros that are to do with using Microsoft Word to prepare a Forum post into the code module “NormalCodesBackUp”.
They come from where I always start putting my macros which is in some default code module God knows where which I never named or created and is in some File I never named or created called “Normal”.
The code module is called NewMacros. I do not have much experience with Word VBA, and my first codes were just done by having the macro recorder turned on whilst manually doing what I wanted. After that I modified the codes a bit and they have been available since to anything I do in word.
NormalMacros.jpg http://imgur.com/TV5YnJ8

Some codes are very simple, so explaining them all may be a bit tedious. I will just go through a few examples. ( I tend to explain a lot in the '_- Green 'comments going off to the right. )

Simple codes for putting single BB Code Code tags pairs in
I mostly got these from a macro recording done while I did what I wanted manually. Then I had some help here http://www.eileenslounge.com/viewtopic.php?f=26&t=25185 http://www.eileenslounge.com/viewtopic.php?f=44&t=26076 to refine them a bit
One further very useful thing I picked up here http://www.eileenslounge.com/viewtopic.php?f=26&t=25188#p195442 is that you have available an extended range of short cut keys which you can use to trigger off a macro.

The start point of most of my codes are to select the text to which a code pair should be added
So say in my Word File I want to change the text,
'comments
to look in my word document as
'comments
This will return me in a final posted Reply in a Thread the following:
'comments
( Note: I am putting the format, ( here coloring green ) , into the Word document of the same formatting that the BB Code Code tag pair will produce in the final forum post )

So I select that text and use in thes case the short cut keys of first
Ctrl+Shift+g
Followed by ( the extended option )
1

This is the code that does this, ( and there may be lots of better ways to do it):


Sub Makro10BBGreen() ' Ctrl+Shift+G,1 https://eileenslounge.com/viewtopic.php?f=26&t=25185#p195286
' Let Selection.Font.Color = 5287936 'Green
' Dim rng As Range: Set rng = Selection.Range
' Dim Txt As String
' Let Txt = rng.Text
' 'Let Txt = "" & Txt & " " 'Added a " " space on the end, so that at end of selection is where I want to be or..
' Let Txt = "" & Txt & ""
' Let rng.Text = Txt
' rng.Select ' Select so that I can ...
' Selection.Collapse Direction:=wdCollapseEnd ' ... "unselect" with an option that takes me to the end of the text
' Selection.Font.Color = wdColorAutomatic ' Put text color back to automatic
' Set rng = Nothing
'Or
With Selection
.Font.Color = 5287936
.Text = "" & .Text & ""
.Collapse Direction:=wdCollapseEnd
.Font.Color = wdColorAutomatic
End With
End Sub


This shows the short cut combination, which is ExPlained in a bit more detail here: http://www.eileenslounge.com/viewtopic.php?f=26&t=25188#p195293
http://wordribbon.tips.net/T008058_Assigning_a_Macro_to_a_Shortcut_Key.html
_1 Display the Word Options dialog box. (In Word 2007 click the Office button and then click Word Options. In Word 2010 and Word 2013 display the File tab of the ribbon and then click Options.)
_2 At the left side of the dialog box click Customize (Word 2007) or Customize Ribbon (Word 2010 and Word 2013).
_3 Near the bottom of the dialog box click the Customize button. Word displays the Customize Keyboard dialog box.
_4 Scroll through the Categories list and select the Macros category. The list at the right side of the dialog box changes to show the currently available macros.
_5 In the Macros list, select the macro you want assigned to the shortcut key.
_6 With the insertion point in the Press New Shortcut Key box, press the shortcut key you want to use. For instance, if you want to use Ctrl+Alt+J, press that.
_7 Just below the Current Keys box you can see whether the shortcut key is already assigned to a different function.
_8 Click on Assign.
( _ I think 7 should read _7 Just to the Left of the Keys…… )
Note the extended options _..
Green1ShortCut.JPG http://imgur.com/zpOZljD
_..you write in Ctrl+Shift+G and then 1. You do not type in a comer , that is done for you. You also do not type in a comer when you use the keys.


Codes for white Space Tricks.
In the first post was discussed the problem with Forum Editors typically “eating” spaces in the posted Reply. I wrote a number of codes, developed here:
http://www.eileenslounge.com/viewtopic.php?f=26&t=22603 http://www.excelforum.com/the-water-cooler/1103850-extra-space-or-spaces-in-text-in-forum-post-bb-code-for-extra-space-2.html#post4329068 to do the “white space trick”
They are discussed in detail in those referenced threads.

BB Code Table Generator ( Spreadsheet screenshot copyable to a Forum Post )
Using Excel 2007 32 bit
Row\Col
E
F

18This is discussed in


19detail from the startof this Thread: http://www.excelforum.com/development-testing-forum/1086445-forum-tools-test-no-reply-needed.html


20and alsoin more Threads then I can remember !
Worksheet: Tabelle3


'_- Here just a few Posts
http://www.excelfox.com/forum/showthread.php/2079-test-BB-Code?p=9821#post9821
http://www.excelfox.com/forum/showthread.php/2079-test-BB-Code/page3
http://www.excelforum.com/development-testing-forum/1161667-messin-round-just-ignore-me.html#post4513357
http://www.excelforum.com/suggestions-for-improvement/949916-how-to-post-a-range-headers-and-data-17.html#post4355361
http://www.excelforum.com/the-water-cooler/1127943-tags-for-coloring-table-cells-for-excelforum-2.html#post4355240
http://www.excelforum.com/excel-programming-vba-macros/1135724-compare-and-find-missing-rows-in-two-sheets-with-different-headings-and-formats-5.html#post4399581
http://www.excelforum.com/the-water-cooler/1068075-just-testing-img-cannot-do-it-in-test-forum-as-img-is-off-there-no-reply-needed-2.html#post4109080

Here is a File where I collected lots of such Tools, all as stand codes rather than Add-ins.
Included are also versions of Rory’s Tool as a simple code.
https://app.box.com/s/zhz7awdag4nl1zs6564s9zzcwp50e4w9
( Note: There is a separate Tool for Eileen’s lounge. In the file is a version for Excel. It is derived from Tools from Hans ( Excel and Word ) http://www.eileenslounge.com/viewtopic.php?f=50&t=1421 http://www.eileenslounge.com/viewtopic.php?f=50&t=2121 )



Codes to remove BB Code in text:
I may discuss these in a bit more detail, just to get the documentation down some where, as I only did it all recently.
Such codes may be of limited use. I needed to do it after a Forum Hic cup wiped out a massive amount of my threads , which I only have as a back up in text including BB Code.

I have
_ a long complicated code, that I did myself, that just works on a simple monochrome text string of the entire text.
and
_ a more sensible code which I got some help with. This will take out the BB Code Code tags but leave the text in the Format it has in the Final Thread. That is to say, the form given by the code looks in Word just as it did in the final form in the Forum post. ( Note, however, that this is only possible as the codes for putting single BB Code Code tags pairs which I used also put the corresponding format into the text in a Word document in the first place )

DocAElstein
03-01-2017, 10:11 PM
VBA Remove BB Code Code Tags in text

In the next post is a code to remove BB Code Code Tags in text

This code is slightly redundant since I was given a simpler one ,
http://www.eileenslounge.com/viewtopic.php?f=26&t=26030&p=202145#p202122
which probably is more Full proof !
But I include it here with description for future reference. I may use it in a following code or codes to cross check the results given.
The code is intended to remove valid BB Code Code Tag sections from a Text string.
In this case, valid means in terms of the syntax, which is basically as follows

Any text or Any text

An arbitrary string is given initially in code section Rem 1)
"gggg245[/8]x[dddAny text"


Then the main code is as follows

Rem 2 Brief Code description
The code works backwards 100 through the whole string. It looks at a character at a time.
120 __ On If finding a ] , it notes the position of it,
140 BcrdEEnd, then keeps going back.
160___If it finds another it notes that as the ] position and carries on going back.
170 It determines the position of a [ , BcrdESt, by looking for a [\
It starts looking again for the next ] ,
250 _____If a ] is found, it checks
260 _____If the next character back is another ], Then it keeps going back. If the next character back was Not a ] , then the position of the ], BcrdSEnd, is
270 noted
A new last loop 290 starts going further back to look for a [
300 ________If it finds a [ , it notes that, BcrdSSt.
320 ________If in the unlikely event that it is a start of an end , like [\ then we have found a second End BB Code Code Tag so we do like_..
BcrdEEnd = BcrdSEnd:
BcrdESt = BcrdSSt:
BcrdSEnd=0:
( BcrdSSt=0 )
_..and go back and start again looking for the start tag. Otherwise the start position of the start tag, BcrdSSt, is noted, then it is finally time to go and think about getting rid of the code tag pair whose positions have now been determined....
430 FkOffCrd:
_..So I come to a point, aptly named, Rem 3) "I think we come here with a complete set of 4 positions". So I try to take the BB Code Code Tags out. As I am going backwards, the new string with the missing Code Tag pair does not mess up me going through the characters as I took off stuff "behind me"
450 I overdo the use of variables here because I can and do, but also because a development of the code might be to look through a list of available BB Code Code Tags to check I have them . I do one quick validity check: I check that the word after the / in the End BB Code code tag is the same as the word in the start BB Code code tag ( that before an = , if there is an = ) . Only
500____ If this condition ( which must be met for a valid BB Code code tag ) is met are the pair of tags removed by replacing them with , . Another condition is also checked: a / in second character of the stop tag.

Either from going through a code section search with possible removal, or ,
540 Else not , we are at the Next posCurrent of the main going backward Loop,
580 , so keep going back looking for another, or a first possible start ( looking from the back ).
Hopefully, for example at line 340, posCurrent would have been reduce to allow for the inner Loops going back in a code tag section search.


_................................

The code returns the string:
gggg245[/8]x[dddAny text

DocAElstein
03-01-2017, 10:12 PM
Code described and ExPlained in last post




Sub LongWayOfDoingIt()
10 Rem 1) Test string
20 Dim strBBCode As String '
30 Let strBBCode = "gggg245[/8]x[ddd]Any text"
40 Dim strRmveBBCode As String: Let strRmveBBCode = strBBCode ' This will be adjusted until finally has no BBCode tag pairs
50 Dim Lstr As Long ' This will be adjusted as necerssary for current length ' Long is very simple to handle, - final memory "size" type is known (123.456 and 000.001 have same "size" computer memory ) , and so a Address suggestion can be given for the next line when the variable is filled in. '( Long is a Big whole Number limit (-2,147,483,648 to 2,147,483,647) If you need some sort of validation the value should only be within the range of a Byte/Integer otherwise there's no point using anything but Long.--upon/after 32-bit, Integers (Short) need converted internally anyways, so a Long is actually faster. )
60 Let Lstr = Len(strBBCode)
70 Rem 2) Loop through and get a BB Code section
80 Dim strBBCodePair As String ' for a found valid pair '
' Prepares "Pointer" to a "Blue Print" (or Form, Questionaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular “Value”, or (“Values” for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. A String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quich checks.. But..http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring-2.html#post44116
90 Dim posCurrent As Long 'Current position in the string' Loop Bound variable Count '_-Main Loop==========================
100 For posCurrent = Lstr To 2 Step -1 'Important to go backwards as we chop off behind us so have a less complicated current position. We look at pos-1 in some code parts so we would error if we went back to less than 2
110 '2a) Check for a ] Most likely a end of end tag ' ---Loop To find ]
120 If Mid(strRmveBBCode, posCurrent, 1) = "]" Then
130 Dim posBBCodeTagSrch As Long '
140 Dim BcrdEEnd As Long: Let BcrdEEnd = posCurrent 'Position of possible End Code Tag End ' ---Loop To Find [/--
150 For posBBCodeTagSrch = posCurrent - 1 To 2 Step -1 'PosCurrent is set here at loop start. ###It is not effected by cardinally sining changing PosCurrent Loop Bound variable caount in Outer main Loop
160 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "]" Then Let BcrdEEnd = posBBCodeTagSrch: GoTo NxtCESPosPos ' If we hit another ] then change the stop tag stop character position and start again to see if is a valid BB code section
170 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "/" And Mid(strRmveBBCode, posBBCodeTagSrch - 1, 1) = "[" Then 'We hit start of a BB Code end tag
180 Dim BcrdESt As Long: Let BcrdESt = posBBCodeTagSrch - 1 'Position of End Code Tag Start
190 Exit For ' We leave this For the End Code Tag Start Search, Exit For with a [ at posBBCodeTagSrch-1
200 Else 'Not found start of end Tag or stop of end Tag.
210 End If
220 NxtCESPosPos: Next posBBCodeTagSrch ' go back in possible BB code string ' ---End Loop to find [/---------------------
230 If posBBCodeTagSrch = 3 Then Exit Sub 'case we never found the start of an End Code Tag
235 '2b) Check for a ] Most Likely end of start tag ' ---Loop to find ]
240 For posBBCodeTagSrch = posBBCodeTagSrch - 2 To 2 Step -1 ' Once again ### the start is set and fixed, the Loop Bound Variable Count will change
250 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "]" Then
260 If Mid(strRmveBBCode, posBBCodeTagSrch - 1, 1) = "]" Then GoTo NxtCSSPosPos ' If we hit another ] then start again to see if is a valid BB code start section
270 Dim BcrdSEnd As Long: Let BcrdSEnd = posBBCodeTagSrch 'Position of possible Start Code Tag End
280 Dim LTagStLoop As Long 'Last loop to find start of start Code Tag
290 For LTagStLoop = posBBCodeTagSrch - 1 To 1 Step -1 '_-Most Inner loop_______to find [/____________
300 If Mid(strRmveBBCode, LTagStLoop, 1) = "[" Then
310 Dim BcrdSSt As Long 'Have to put it here, - I may occaisionally have to set it to 0 in next line
320 If Mid(strRmveBBCode, LTagStLoop + 1, 1) = "/" Then Let BcrdEEnd = BcrdSEnd: Let BcrdSEnd = 0: Let BcrdESt = LTagStLoop: Let BcrdSSt = 0: Let posBBCodeTagSrch = LTagStLoop: GoTo NxtCSSPosPos ' Found a second end Code Tag. So change the previous found start and stop , and adjust the Loop Bound variable Count appropriately for a new search for a start Code Tag
330 Let BcrdSSt = LTagStLoop
340 Let posCurrent = BcrdSSt 'End of Code Tag section search
350 GoTo FkOffCrd ' We leave this For the start Code Tag Start Search and go to Fuk Off Crd:
360 Else ' Still looking for start of start Code Tag
370 End If
380 Next LTagStLoop '_- End Most inner loop_____________________to find [/_____________________________
390 If LTagStLoop = 1 Then GoTo TheEnd 'Case I think we failed to find a start start [ for the complete possible Code Tag section search
400 Else 'Not found end of start Tag or start of start Tag
410 End If
420 NxtCSSPosPos: Next posBBCodeTagSrch ' go back in possible BB code string' ---End Loop to find ]
425 If posBBCodeTagSrch = 0 Then GoTo TheEnd ' For any outer search failed to find a ] at all or a search for matching start tag that was fruitless
430 FkOffCrd: Rem 3) "I think we come here with a complete set of 4 positions"
440 If BcrdEEnd <> 0 And BcrdESt <> 0 And BcrdSEnd <> 0 And BcrdSSt <> 0 Then 'Just to check'
450 Dim SttBcrd As String, StpBcrd As String ' Start and stop tags as coplete strings including [ and ]
460 Let SttBcrd = Mid(strRmveBBCode, BcrdSSt, BcrdSEnd - BcrdSSt + 1) ' ' like |Color=Red|
465 Let StpBcrd = Mid(strRmveBBCode, BcrdESt, BcrdEEnd - BcrdESt + 1) ' ' like |/Color|
470 Dim SttWrd As String, StpWrd As String
480 Let StpWrd = Mid(StpBcrd, 3, Len(StpBcrd) - 3) ' like Color from |/Color| - Whole Word, from 3rd Chr , for Length as WholeWord-3
490 Let SttWrd = Mid(SttBcrd, 2, Len(StpWrd)) ' like Color from |Color=Red|
500 If UCase(SttWrd) = UCase(StpWrd) And Mid(StpBcrd, 2, 1) = "/" Then 'Ucase allows for differences in cases And Mid(SttBcrd, Len(SttWrd) + 2, 1) = "=" Then
510 Let strRmveBBCode = Replace(strRmveBBCode, SttBcrd, "", 1, 1) ' Replace in ( strRmveBBCode , the start tag , with no string , start loooking from and return from character 1 )
515 Let strRmveBBCode = Replace(strRmveBBCode, StpBcrd, "", 1, 1)
520 Else 'No shortening of string for non matching tag word
530 End If
540 Else 'No shortening of string for not all 4 [ and ] found. Not sure if I ever come here..
550 End If
560 Else ' no last ] of a possible Code section yet, so keep going back down in the main string , main loop
570 End If
580 Next posCurrent '_-===Main Loop============================================== ==========================================
590 TheEnd:
600 MsgBox Prompt:="" & strRmveBBCode & "": Debug.Print "" & strRmveBBCode & "" 'Hit Ctrl+g when in VB Editor Window, reveal Immediate window after code run
End Sub

DocAElstein
03-01-2017, 10:14 PM
The VBA code in the last few posts is a bit of a long way around of doing what can be done in a Word Dialogue box type thing using Wild things:
http://www.gmayor.com/replace_using_wildcards.htm
http://imgur.com/4Nqj1HP

The problem is getting at the Wild Things needed in the Wild Find String.

I can't do it. But Hans and Paul did it for me here:
http://www.eileenslounge.com/viewtopic.php?f=26&t=26030#p202107

Here is my attempt at an 'ExPlanation of the solution:


Wild Things. You make my heart sing. They make everything….. Groovy

Wild Things. You make my heart sing. They make everything….. Groovy
http://listenonrepeat.com/watch/?v=Hce74cEAAaE#The_Troggs_-_Wild_Thing
Wild things…. I think I hate you .. But I wanna know for sure… so

A Summary :)
As example. We want to remove the start and stop tags in a sample string containing a start and stop tag such as this_..

This is green This 'aint matey

_.. What we finally want is this:

This is green This 'aint matey

We use a combination of Wild things , or like a pattern to search for [ Find ] any bits like _..

This is green
_.. and [ Replace ] that "Find"ed with

This is green

We can do, it Wildly, man, as follows:
As always the search is done from left to right

The way I do it below is probably not the most efficient way, in fact it is probably pretty stupid, but is just to demo the idea
Optional use of ( ) in the Wild thing search string
We can use brackets ( ) , optionally , to identify, ( for later use ) , the exact string parts found by the constituent Wild things in the ( ) in which they are in:
So in this example we will use a ( ) for
_ the Wild things that find the color so that the actual word color can be used again in the same wild stuff string, so as to make sure that we find in the end tag the matching word to that in the start tag.
_ Also we need a ( ) to identify the wild things that Find This is green , as we want to use that in , or rather for the complete, Replace string.
A bracket is identified by , for example, \2 if I want to reference the actual string found by the wild things we enclose in the second ( )

Build up final Wild thing Replace string, left to right, by breaking string we want up into bits. Each bit will be found by a Wild thing or things
So we are looking to break the to search for Wild [ Find ] Thing string down thus:

[ & ( AnythingWithout=or] ) & anything & ] & (Anything) & [\ & \1 & ]
So I am breaking it down in to 8 bits. So I need 8 sections of wild stuff to Find those.
\1 is at the 7th position and refers to what is actually found by the search for ( AnythingWithout=or] ) at position 2 ( which is bracket ( ) number 1 )


Excel starts at the left. What no literature really states clearly ( and is only obvious once you know it ) is this:
_ For most sections, Excel keeps going to the right until it Finds what the Wild thing tells it to. That is then stored, but only if that found string also has joined to it the string type in the next section's Wild thing. Those two sections are then stored ( as well as storing separately if either of those two sections are enclosed in ( ) ), but only if that found string also has joined to it the string type in the next section's Wild thing. That is then stored, but only if that found string also has joined to it the string type in the next section's Wild thing. ……..etc.
A common Wild thing is * . This means anything characters and any amount. This will only include, however, anything up to if and when the next Wild thing is satisfied.

The 7th Wild thing I already have which is \1 which is referring to the 1st bit enclosed in a ( ) , which is the second bit in the broken up string , ( which is anything without a = or a ] . In our example this will be color) . Note: The number refers to the number from the left of any ( ) that I may have included, not the actual sections.
Just to make that last point clear, and to demonstrate another, I will do this_..

[ & ( AnthingWithout=or] ) & ( Anything & ] ) & (Anything) & [/ & \1 & ]
_.. so my Replace is then \3 . I do not need the second ( ___ ) , which I could reference by \2, ( and it can help to result in an "expression too complex" error ! ).
I put the second ( ___ ) in also to demo that a ( __ ) can include more than one wild bit



So here is one example Find sting with Wild things that "works" ( I added spaces to show better the 8 sections, but in use those spaces must be removed ). There are three optional ( ) sections. The second ( ) section encloses two Wild thing sections: Those are the third and forth counting from the left.


[\[] ([!\]=]@) (* \]) (*) \[/ (\1) \]
This is the actual Wild Find string
___ [\[]([!=\]]@)(*\])(*)\[/(\1)\]

To '_- ExPlain the 8 parts:
Part 1 [\[]
Excel start "looking" from the left to find a [
As a general rule Wild things are enclosed in a [ ] pair to identify them as such. So a [ ] is a Wild thing. They do not always have to be enclosed in a [ ], as is the case here. Here we are effectively looking to Find a single simple character, [.
( In the final Find string, only the second Wild section needs to be enclosed partly in a [ ] pair ).
So this section written as \[ instead is just as good. I suspect my use of the extra [ ] here does not have any bad effects, as it might be that the final string would be at compile or whatever reduced to \[ in either use of \[ or [\[]
We need to use the Wild thing, \ , quite a bit , in our total string for the same reason that we do here: This is because the \ has another use in Wild things in addition to the already discussed way like \7 ( where 7 would be for the 7th ( ) ). This other use of \ is to allow us to use characters as simple text which have a specific use in Wild things, so that Excel knows that we want to use them as their literal text string, rather than as Wild thing. Here it is needed for the first [ which we want to find.
( It follows that if we were looking for a \, then we would need to use \\ )
In our example string we find with this first Wild thing section the first [

Part 2 ([!\]=]@)
As noted the ( ) allows the string actually found in this Wild bit to be used later to the right via the reference \1.
As for this:
[!\]=]@ ( which could just as well be written [!=\]]@ )
We need a [ ] pair here, as within that is part of the Wild instructions for what to search for , and that has a further Wild instruction, @ , applied to that.
So in such a [ ] pair we would normally expect some specific wild stuff
Here the Wild thing, ! , means we search for any character other than those after included up to the closing tag ]. In our sample string , our first Wild bit found the first [ which now has added on any string at the next character if it is not a = or a ]
So this part of the second wild bit will find c in our sample string. If we had no other wild instructions here, then Excel would be content/ satisfied with that c. That would be joined on to the first [ found, so our result so far would be [c . In effect Excel stops going to the right when it is satisfied, and goes on to the next Wild bit. But we have another wild instruction here: The @ instructs to look for any amount of characters meeting the conditions before it, in this case the conditions in the [ ]. So the "Find" will stop finding characters when it no longer has a not = or a not ]. In our sample string the characters meeting the conditions are tacked on to a [ so will be will be =]@ has actually found and what the brackets ([!\]=]@) can be thought of as "holding" is color.
An alternative for @ would be {1,} which looks for between 1 and any amount of what is before it.
If we had used {1,4} or {2,4} instead of @ we would have so far for the complete found string [colo
If we had used {5,5} we would not have found a matching code tag word with less than 5 characters.

Parts 3 and 4 (*\])
This is unnecessarily in ( ) . *\] will do
The literature says * looks for any amount of anything. I think that is not strictly correct, or at least, explains it badly. It would appear to look for any amount of anything only until the next wild condition is met. That is why I chose to put it in ( ) just to demo the dependence, as it were. But this (*)(\]) or this *\] would work just as well (*)(\]).
Once again the \ is required for telling Excel that we want it to recognise ] as a string rather than a specific Wild thing. For this section , with my example string, I get from this complete 2 part Wild section
=green]
If our code tags were of the form like: ]SomeBoldText , then the search would have "stopped before it started", as it were, as the ] would have "stopped" it
The combination of the 2 part Wild sections in this case would return just the single text character ]


Parts 5 and 6 (*)\[/
I contradict what I said in the last section slightly by using a ( ) around the * . Once again the * does nothing useful without the next wild bit to "stop" it. But what it does Find before it "stops" is what we actually need for Replace string. Hence I need a ( ) to reference what it Finds. This total Part 5 and part 6 section returns in our example
This is green[/
and the part referenced inside the ( ) is
This is green

Part 7 (\1)
As discussed already here the Wild thing, \1 , instructs to Find a string equal to that actual text found in the first ( ) if it is just before the next to be found ( which we will see in the next Part is the last character pair found, [/ ). The actual string found by [!\]=]@ in Part 2 , was , in our example the text color

Part 8 \]
Finally only a complete final Find attempt is successful if the last character is a ] , that is to say if the character after the text, in our example, the second color, is a ]

_...

The Final "Find"ed String for our example would be

[ & color & =Green & ] & This is green & [/ & color & ]

DocAElstein
03-01-2017, 10:17 PM
Here is a simple code to use the Find and Replace discussed in the last Post
The code should go in a code module in a WORD .docm File
Before rung the code, a text which includes BBCode Code Tags , should be selected in a Word document.

The Code makes a temporary File, "TempBBCodeCopy1.docx", holding the original selected text, then removes the BB Code Code Tags from the text and saves that as another temporary File, "TempNoBBCodeCopy2.docx"




Sub WegDaMitHansPaulAlan() ' http://www.eileenslounge.com/viewtopic.php?f=26&t=26030#p202223
Rem Code Part 1) make two temporary Word Files with and without BB Code
Rem 1) Copy selection to Clipboard
Selection.Copy
Rem 2) Make temporary WORD document
Documents.Add: ActiveDocument.Content.Paste
' 2b) Copy of Full Text with BB Code
Dim FullFilePathAndFullNameBBCode As String
ActiveDocument.SaveAs Filename:="TempBBCodeCopy1.docx", FileFormat:=wdFormatXMLDocument
Let FullFilePathAndFullNameBBCode = ActiveDocument.Path & "\" & ActiveDocument.Name
Rem 3) Replace Code tag pairs with what is in between
Selection.WholeStory
With Selection.Find
.ClearFormatting: .Replacement.ClearFormatting
.Wrap = wdFindStop
.MatchWildcards = True '
.Text = "[\[]([!=\]]@)(*\])(*)\[/(\1)\]" ' 8 sections, 4 identified with ( ) but I only need two ( )
.Replacement.Text = "\3" ' The third of the 4 sections identified with a ( )
.Execute Replace:=wdReplaceAll
End With
' 3b) Copy of Colored Text without BB Code Code tags
Dim FullFilePathAndFullNameNoBBCode As String
ActiveDocument.SaveAs Filename:="TempNoBBCodeCopy2.docx", FileFormat:=wdFormatXMLDocument
Let FullFilePathAndFullNameNoBBCode = ActiveDocument.Path & "\" & ActiveDocument.Name
Rem 4) "Reset the "Find Replace Text Dialogue" "Thing" "
ActiveDocument.Select
Selection.WholeStory
With Selection.Find
.ClearFormatting: .Replacement.ClearFormatting: .Text = "": .Replacement.Text = "": .Forward = True: .Wrap = wdFindAsk: .Format = False: .MatchCase = False: .MatchWholeWord = False: .MatchKashida = False: .MatchDiacritics = False: .MatchAlefHamza = False: .MatchControl = False: .MatchWildcards = False: .MatchSoundsLike = False: .MatchAllWordForms = False '
End With
Rem 5) Option to close / kill document
ActiveDocument.Close (wdDoNotSaveChanges)
'Kill FullFilePathAndFullNameBBCode
'Kill FullFilePathAndFullNameNoBBCode
End Sub ' End Code Part 1)





__________________________________________________ _______________________________________

This not too relavent for this Post, just wanted to jot it down quick:

'EP Dim: For Object variables: Address location to a "pointer". That has all the actual memory locations (addresses) of the various property values , and it holds all the instructions what / how to change them , should that be wanted later. That helps to explain what occurs when passing an Object to a Call ed Function or Sub Routine By Val ue. In such an occurrence, VBA actually passes a copy of the pointer. So that has the effect of when you change things like properties on the local variable , then the changes are reflected in changes in the original object. (The copy pointer instructs how to change those values, at the actual address held in that pointer). That would normally be the sort of thing you would expect from passing by Ref erence. But as that copy pointer "dies" after the called routine ends, then any changes to the Addresses of the Object Properties in the local variable will not be reflected in the original pointer. So you cannot actually change the pointer.)
'EP Set: Fill or partially Fill: Setting to a Class will involve the use of an extra New at this code line. I will then have an Object referred to as an instance of a Class. At this point I include information on my Pointer Pigeon hole for a distinct distinguishable usage of an Object of the Class. For the case of something such as a Workbook this instancing has already been done, and in addition some values are filled in specific memory locations which are also held as part of the information in the Pigeon Hole Pointer. We will have a different Pointer for each instance. In most excel versions we already have a few instances of Worksheets. Such instances Objects can be further used., - For this a Dim to the class will be necessary, but the New must be omitted at Set. I can assign as many variables that I wish to the same existing instance
'_-So A variable in VBA is like the Link to the part of a URL string reducing size site where a few things about the actual Final site is informed about. This area in that site, like a pigion Hole to which the variable refers, ( the "pigeon hole" location address, and all its contents would be defined as the "Pointer". Amongst other things it has a link, a "Pointing part", pointing to actually where all the stuff is

DocAElstein
03-01-2017, 10:19 PM
Full Code "Belt and Braces" in Word Find Replace & String Manipulation of initial Text String in Clipboard

This code is simply doing the two ways to remove BB Code code tag pairs from a copied to the clipboard Text from a Word document.
A check is then done Finally to see if the two raped from tags strings are the same.

I would not be surprised if a fail in the strings match just means that the second method, ( my long string manipulation way ) is getting it wrong.. Lol.. but never mind :) ***
***Edit: - like I just did: It will not work for nested BBCode code tags like

Issue Forum for Issues suggestions for improvement Forum for Issues obfuscation
This is OK
Issue Forum for Issues suggestions for improvement Forum for Issues obfuscation
:rolleyes:

That will do for this one, I guess I will have to do a recursion wonk to get a version working with nested BB Code Tag code tags,
_.____________-
:rolleyes:
Ok. Here we go:
This code _..
Sub BBCodeCodeTagsWegDaMit2AlanHansPaul2()
_.. is mostly just splicing together codes
Sub WegDaMitHansPaulAlan()
and
Sub LongWayOfDoingIt()
along with adding a short section, Rem 10a) to check that the strings are the same. That is to say the
Full Story selection text from the modified ( removed BB Code code tags ), NewWordText for Code Part 1)
is
compared with the final RapedText from the long string manipulation Code part 2)

The code is all one code and broken down into this and the next three posts

Code part 1 of 4 parts ( all following parts to be copied directly under the preceding part in the same code module.

Sub BBCodeCodeTagsWegDaMit2AlanHansPaul2() ' http://www.excelforum.com/development-testing-forum/1086445-forum-tools-test-no-reply-needed-4.html#post4586680
' === Code assumes you have a Word File open, and have selected some Text
' One way is automating doing it in Word. "Wild Things. You make my heart sing. They make everything….. Groovy" '_- http://www.eileenslounge.com/viewtopic.php?f=26&t=26030#p202322
Rem 0) ' Just mucking about a bit with refering to Word documents
' Documents.Item("eileenslounge.docm").Activate
'Dim DocNme As String ' ' Prepares "Pointer" to a "Blue Print" (or Form, Questionaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular "Value", or ("Values" for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. A String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quich checks.. But..http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring-2.html#post44116
' Let DocNme = ActiveDocument.Name ' ' '_-So A variable in VBA is like the Link to the part of a URL string reducing size site where a few things about the actual Final site is informed about. This area in that site, like a pigion Hole to which the variable refers, ( the "pigeon hole" location address, and all its contents would be defined as the "Pointer". Amongst other things it has a link, a "Pointing part", pointing to actually where all the stuff is
Dim Doc As Document 'A variable in VBA is like the Link to the part of a URL string reducing size site where a few things about the actual Final site is informed about. This area in that site, like a pigion Hole to which the variable refers, ( the "pigeon hole" location address, and all its contents would be defined as the "Pointer". Amongst other things it has a link, a "Pointing part", pointing to actually where all the stuff is
Set Doc = ActiveDocument 'EP Set: Fill or partially Fill: Setting to a Class will involve the use of an extra New at this code line. I will then have an Object referred to as an instance of a Class. At this point I include information on my Pointer Pigeon hole for a distinct distinguishable usage of an Object of the Class. For the case of something such as a Workbook this instancing has already been done, and in addition some values are filled in specific memory locations which are also held as part of the information in the Pigeon Hole Pointer. We will have a different Pointer for each instance. In most excel versions we already have a few instances of Worksheets. Such instances Objects can be further used., - For this a Dim to the class will be necessary, but the New must be omitted at Set. I can assign as many variables that I wish to the same existing instance
Rem Code Part 1) make two temporary Word Files with and without BB Code

DocAElstein
03-01-2017, 10:20 PM
Code part 2 of 4 parts



Rem Code Part 1) make two temporary Word Files with and withouut BB Code
Rem 1) Copy selection to Clipboard
Selection.Copy
Rem 2) Make temporary WORD document 'Bit of a bodge to get the text in a selection: create a Word file and paste to it
Dim NextTempDoc As Document '
Documents.Add: ActiveDocument.Content.Paste 'Make a File Copy in current Application based on Default Type : And Paste from Clipoard ( ...!!!...our original selected text ) using the Default Copy which should at least have all the text, which is all we are interested in here.
Set NextTempDoc = ActiveDocument ' Do this in case i muck about- I do not want to inadvertently close or kill the wrong document
'2b) Copy of Full Text with BB Code
Dim FullFilePathAndFullNameBBCode As String ' 'Prepares "Pointer" to a "Blue Print" (or Form, Questionnaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular “Value”, or (“Values” for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quick checks.. But...http://www.mrexcel.com/forum/excel-q...html#post44116
NextTempDoc.SaveAs FileName:="TempBBCodeCopy1.docx", FileFormat:=wdFormatXMLDocument 'Without this the document will not really "exist jet". It has a tempory name ( Used in Windows referrence ), but no path.
Let FullFilePathAndFullNameBBCode = NextTempDoc.Path & "\" & ActiveDocument.Name
Rem 3) From Han's Text Find Replacement Dialogue 'http://www.eileenslounge.com/viewtopic.php?f=26&t=22603#p175712
'3a) Take out all BB Code
Selection.WholeStory 'Selects whole document which here is just our selection of interest from the original document
Dim StrOrg As String: Let StrOrg = Selection.Text '11a)6b)' Original Text to use in string manipultion code of Code Part 2)
With Selection.Find 'This is the VBA code ( or very similar ) used by Excel when Using the Find eplace text Dialogue box. So this is an improved version of what a macro recording would give.
.ClearFormatting: .Replacement.ClearFormatting ' Don't use formating, ? not sure this comes into the equation ??
.Wrap = wdFindStop ' Tell Word not to continue past the end of the selection ( And therefore prevents also a display Alert asking )
.MatchWildcards = True
.Text = "[\[]([!=\]]@)(*\])(*)\[/(\1)\]" ' 8 sections, 4 identified with ( ) but I only need two ( )
.Replacement.Text = "\3" ' The third of the 4 sections identified with a ( )
.Execute Replace:=wdReplaceAll ' Replace all within selection. This is the "OK" button!
End With
Selection.WholeStory: Dim NewWordText As String: Let NewWordText = Selection.Text '´11a) New text for comparison with result from Code Part 2)
'3b) Copy of Colored Text in Word File without BB Code Code tags
Dim FullFilePathAndFullNameNoBBCode As String
NextTempDoc.SaveAs FileName:="TempNoBBCodeCopy2.docx", FileFormat:=wdFormatXMLDocument 'Without this the document will not really "exist jet". It has a tempory name ( Used in Windows referrence ), but no path.
Let FullFilePathAndFullNameNoBBCode = NextTempDoc.Path & "\" & ActiveDocument.Name
Rem 4) "Reset the "Find Replace Text Dialogue" "Thing" ". if you do not there may be some changed setting there that could catch you out next time you use it.
NextTempDoc.Select ' Re select the...( actually this line alone seems to do it )
Selection.WholeStory '...whole document
With Selection.Find
.ClearFormatting: .Replacement.ClearFormatting: .Text = "": .Replacement.Text = "": .Forward = True: .Wrap = wdFindAsk: .Format = False: .MatchCase = False: .MatchWholeWord = False: .MatchKashida = False: .MatchDiacritics = False: .MatchAlefHamza = False: .MatchControl = False: .MatchWildcards = False: .MatchSoundsLike = False: .MatchAllWordForms = False '
End With
Rem 5) Optiion to close / kill document
NextTempDoc.Close (wdDoNotSaveChanges) ' Giving the option will also prevent being asked for it. You must close. VBA will not let you kill an open sheet, as you are affectively working on a copy, and VBA is assumng the Original can be got at by saving for example. http://www.mrexcel.com/forum/excel-questions/920451-excel-macro-files.html#post4425428
'Kill FullFilePathAndFullNameBBCode ' Use the Kill wisely!!!! - where this goes there 'aint no coming back!!
'Kill FullFilePathAndFullNameNoBBCode

Rem Code Part 2 Put text without BB code into clipboard
Rem 6) Use data Object ( assumes we copied to the Clipboard )
'1 a) Data Object to get the data from the clipboard.
'_- ExPlanation Dim :'_-: For Object variabls: Address location to a "pointer". That has all the actual memory locations (addresses) of the various property values , and it holds all the instructions what / how to change them , should that be wanted later. That helped explain what occurs when passing an Object to a Call ed Fucntion or Sub Routine By Val ue. In such an occurance, VBA actually passes a copy of the pointer. So that has the effect of when you change things like properties on the local variable , then the changes are reflected in changes in the original object. (The copy pointer instructs how to change those values, at the actual address held in that pointer). That would normally be the sort of thing you would expect from passing by Ref erence. But as that copy pointer "dies" after the called routine ends, then any changes to the Addresses of the Object Properties in the local variable will not be reflected in the original pointer. So you cannot actually change the pointer.)
'_- Explanation Set :'_-: Fill or partially Fill: Setting to a Class will involve the use of an extra New at this code line. I will then have an Object referred to as an instance of a Class. At this point I include information on my Pointer Pigeon hole for a distinct distinguishable usage of an Object of the Class. For the case of something such as a Workbook this instancing has already been done, and in addition some values are filled in specific memory locations which are also held as part of the information in the Pigeon Hole Pointer. We will have a different Pointer for each instance. In most excel versions we already have a few instances of Worksheets. Such instances Objects can be further used., - For this a Dim to the class will be necessary, but the New must be omitted at Set. I can assign as many variables that I wish to the same existing instance
'Dim objCliTextCopied As DataObject '**Early Binding. This is for an Object from the class MS Forms. This will be a Data Object of what we "send" to the Clipboard. So I name it CLIpboardSend. But it is a DataObject. It has the Methods I need to send text to the Clipboard
' Set objCliTextCopied = New DataObject '**Must enable Forms Library: In VB Editor do this: Tools -- References - scroll down to Microsoft Forms 2.0 Object Library -- put checkmark in. Note if you cannot find it try OR IF NOT THERE..you can add that manually: VBA Editor -- Tools -- References -- Browse -- and find FM20.DLL file under C:\WINDOWS\system32 and select it --> Open --> OK. http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/
' ( or instead of those two lines Dim obj As New DataObject ). or next two lines are.....Late Binding equivalent'
Dim objCliTextCopied As Object ' Late Binding equivalent' If you declare a variable as Object, you are late binding it. http://excelmatters.com/2013/09/23/vba-references-and-early-binding-vs-late-binding/
Set objCliTextCopied = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") ' http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/
'6a) Original text string from '11a) The line below means I have nothing to do with the Clipboard yet' - see furhter to the right for .Geting From Clipboard for if it had been in it ' 'Put all? Clipboard Infomation into Data Object
objCliTextCopied.SetText Text:=StrOrg ' I am messing about putting this in data object, then taking it out on 6b) , but I just wanted the code to be more flexible for later use. ' ''objCliTextCopied.GetFromClipboard 'All that is in the Clipboard goes in this Data Object initial instance of the Class This line does not seem to be necerssary for the next Geting Text bit

DocAElstein
03-01-2017, 10:22 PM
Code Part 3 of 4 parts


'6b) get code as long string String. This can be very long
Dim TextWithBBCodeEnit As String ' 'Prepares "Pointer" to a "Blue Print" (or Form, Questionnaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular "Value", or ("Values" for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quick checks.. But...http://www.mrexcel.com/forum/excel-q...html#post44116
Let TextWithBBCodeEnit = objCliTextCopied.GetText() ''retrieve the text in this instance of the Class. ( Our code as a String with probably BB Code Code tags, vbCr vbLf etc.
Rem 7) Determine length of original text
Dim LenText As Long ' ' Long is very simple to handle, - final memory "size" type is known (123.456 and 000.001 have same "size" computer memory ) , and so a Address suggestion can be given for the next line when the variable is filled in. '( Long is a Big whole Number limit (-2,147,483,648 to 2,147,483,647) If you need some sort of validation the value should only be within the range of a Byte/Integer otherwise there's no point using anything but Long.--upon/after 32-bit, Integers (Short) need converted internally anyways, so a Long is actually faster. )
Let LenText = Len(TextWithBBCodeEnit)
MsgBox prompt:="Text with BB Code Character count is " & LenText
Rem 8) Take out BB Code bits from text string.
40 Dim strRmveBBCode As String: Let strRmveBBCode = TextWithBBCodeEnit ' = strBBCode ' This will be adjusted until finally has no BBCode tag pairs
50 Dim Lstr As Long ' This will be adjusted as necerssary for current length ' Long is very simple to handle, - final memory "size" type is known (123.456 and 000.001 have same "size" computer memory ) , and so a Address suggestion can be given for the next line when the variable is filled in. '( Long is a Big whole Number limit (-2,147,483,648 to 2,147,483,647) If you need some sort of validation the value should only be within the range of a Byte/Integer otherwise there's no point using anything but Long.--upon/after 32-bit, Integers (Short) need converted internally anyways, so a Long is actually faster. )
60 Let Lstr = Len(TextWithBBCodeEnit) ' Len(strBBCode)
70 Rem 2) Loop through and get a BB Code section
80 Dim strBBCodePair As String ' for a found valid pair '
' Prepares "Pointer" to a "Blue Print" (or Form, Questionaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular "Value", or ("Values" for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. A String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quich checks.. But..http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring-2.html#post44116
90 Dim posCurrent As Long 'Current position in the string' Loop Bound variable Count '_-Main Loop==========================
100 For posCurrent = Lstr To 2 Step -1 'Important to go backwards as we chop off behind us so have a less complicated current position. We look at pos-1 in some code parts so we would error if we went back to less than 2
110 '2a) Check for a ]
120 If Mid(strRmveBBCode, posCurrent, 1) = "]" Then
130 Dim posBBCodeTagSrch As Long 'For search through possible valid BBCode Section'_-Loop for Pos tag pair section--
140 Dim BcrdEEnd As Long: Let BcrdEEnd = posCurrent 'Position of possible End Code Tag End
150 For posBBCodeTagSrch = posCurrent - 1 To 2 Step -1 'PosCurrent is set here at loop start. ###It is not effected by cardinally sining changing PosCurrent Loop Bound variable caount in Outer main Loop
160 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "]" Then GoTo NxtCESPosPos ' If we hit another ] then start again to see if is a valid BB code section
170 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "/" And Mid(strRmveBBCode, posBBCodeTagSrch - 1, 1) = "[" Then 'We hit start of a BB Code end tag
180 Dim BcrdESt As Long: Let BcrdESt = posBBCodeTagSrch - 1 'Position of End Code Tag Start
190 Exit For ' We leave this For the End Code Tag Start Search, Exit For with a [ at posBBCodeTagSrch-1
200 Else 'Not found start of end Tag or stop of end Tag.
210 End If
220 NxtCESPosPos: Next posBBCodeTagSrch ' go back in possible BB code string
230 If posBBCodeTagSrch = 3 Then Exit Sub 'case we never found the start of an End Code Tag
240 For posBBCodeTagSrch = posBBCodeTagSrch - 2 To 2 Step -1 ' Once again ### the start is set and fixed, the Loop Bound Variable Count will change
250 If Mid(strRmveBBCode, posBBCodeTagSrch, 1) = "]" Then
260 If Mid(strRmveBBCode, posBBCodeTagSrch - 1, 1) = "]" Then GoTo NxtCSSPosPos ' If we hit another ] then start again to see if is a valid BB code start section
270 Dim BcrdSEnd As Long: Let BcrdSEnd = posBBCodeTagSrch 'Position of possible Start Code Tag End
280 Dim LTagStLoop As Long 'Last loop to find start of start Code Tag
290 For LTagStLoop = posBBCodeTagSrch - 1 To 1 Step -1 '_- Second inner loop___________________________
300 If Mid(strRmveBBCode, LTagStLoop, 1) = "[" Then
310 Dim BcrdSSt As Long 'Have to put it here, - I may occaisionally have to set it to 0 in next line
320 If Mid(strRmveBBCode, LTagStLoop + 1, 1) = "/" Then Let BcrdEEnd = BcrdSEnd: Let BcrdSEnd = 0: Let BcrdESt = LTagStLoop: Let BcrdSSt = 0: Let posBBCodeTagSrch = LTagStLoop: GoTo NxtCSSPosPos ' Found a second end Code Tag. So change the previous found start and stop , and adjust the Loop Bound variable Count appropriately for a new search for a start Code Tag
330 Let BcrdSSt = LTagStLoop
340 Let posCurrent = BcrdSSt 'End of Code Tag section search
350 GoTo FkOffCrd ' We leave this For the start Code Tag Start Search and go to Fuk Off Crd:
360 Else ' Still looking for start of start Code Tag
370 End If
380 Next LTagStLoop '_- Second inner loop______________________________________________ __________________
390 If LTagStLoop = 1 Then GoTo TheEnd 'Case we found a start start [ at 1 or failed to find a start start [ for the complete possible Code Tag section search
400 Else 'Not found end of start Tag or start of start Tag
410 End If
420 NxtCSSPosPos: Next posBBCodeTagSrch ' go back in possible BB code string'_-Loop for Pos tag pair section-----------------

DocAElstein
03-01-2017, 10:24 PM
Code part 4 of 4 parts




430 FkOffCrd: Rem 3) "I think we come here with a complete set of 4 positions"
440 If BcrdEEnd <> 0 And BcrdESt <> 0 And BcrdSEnd <> 0 And BcrdSSt <> 0 Then 'Just to check'
450 Dim SttBcrd As String, StpBcrd As String ' Start and stop tags
460 Let SttBcrd = Mid(strRmveBBCode, BcrdSSt, BcrdSEnd - BcrdSSt + 1): Let StpBcrd = Mid(strRmveBBCode, BcrdESt, BcrdEEnd - BcrdESt + 1)
470 Dim SttWrd As String, StpWrd As String ' like |Color=Red|, |/Color|
480 Let StpWrd = Mid(StpBcrd, 3, Len(StpBcrd) - 3) ' like Color from |/Color| - Whole Word, from 3rd Chr , for Length as WholeWord-3
490 Let SttWrd = Mid(SttBcrd, 2, Len(StpWrd)) ' like Color from |Color=Red|
500 If UCase(SttWrd) = UCase(StpWrd) And Mid(StpBcrd, 2, 1) = "/" Then 'Ucase allows for differences in cases And Mid(SttBcrd, Len(SttWrd) + 2, 1) = "=" Then
510 Let strRmveBBCode = Replace(strRmveBBCode, SttBcrd, "", 1, 1) ' Replace in ( strRmveBBCode , the start tag , with no string , start loooking from and return from character 1 )
515 Let strRmveBBCode = Replace(strRmveBBCode, StpBcrd, "", 1, 1)
520 Else 'No shortening of string foe invalid tag word
530 End If
540 Else ' no last ] of a possible Code section yet, so keep going back down in the main string
550 End If
560 Else
570 End If
580 Next posCurrent '_-===Main Loop============================================== ==========================================
'590 TheEnd:
600 MsgBox prompt:="" & strRmveBBCode & "": Debug.Print "" & strRmveBBCode & "" 'Hit Ctrl+g when in VB Editor Window, reveal Immediate window after code run
Dim RapedText As String: Let RapedText = strRmveBBCode ' TextWithBBCodeEnit with BB Code Code tags removed
Rem 9) This a Another Object from class to be sure we have the data in the Clipboard
'Dim objDat As DataObject
'Set objDat = New DataObject 'Set to a new Instance ( Blue Print ) of dataobject
Dim objDat As Object
Set objDat = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
'9b) Put in (and Get back from clipboard) the raped text.
objDat.SetText Text:=RapedText 'Make Data object's text equal to original text without the BB Code Code Tags
objDat.PutInClipboard 'Place current Data object into the Clipboard
objDat.GetFromClipboard 'All that is in the Clipboard goes in this Data Object second instance of the Class.
Dim TxtOut As String: Let TxtOut = objDat.GetText() 'retrieve the text in this second instance of the Class. ( In this case all in it is the text and possibly vbCr and vbLf )
MsgBox prompt:="You dumped in Clipboard this " & vbCr & RapedText & vbCr & "and if you try to get it, you should get" & vbCr & TxtOut & ""
Rem 10a) Code Part 3) Belt and braces check. A check is then done finally to see if the two raped from tags strings are the same
If NewWordText <> RapedText Then MsgBox prompt:="Text from Word Dialogue Box Find Replace Wild card way, and " & vbCrLf & "Long String manipulation way are not the same. Oh dear"
'10b) Tidy up.
TheEnd: ' ( Come here always, even on a unpredictable error ) or i wouod If i had an error Handler, Lol.
Set objDat = Nothing ' Good practice... maybe....
Set objCliTextCopied = Nothing ' ....... http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring.html#post4414065

End Sub

DocAElstein
03-01-2017, 10:26 PM
One problem noted in the previous codes was that the case of nested BB Code tag pairs, the codes did not work. At many forums such nesting of this form is permitted in BB codes.
Comments Highlight Comments
The returned result is
Comments Highlight Comments

None of the codes discussed so far will work for such a case.
Should the Code tag type be dissimilar, such as_..

Title
_..then at least the Find Replace Wildcard Code will work for that by virtue of matching in the String first, for example, in the above example, _..
__ CENTER __ __ __ __ CENTER __
_.. then
__ B __ __ __ __ B __
However my Long string manipulation code will not even work for that.

I have done a Long string manipulation code to be discussed in this and the following posts which , I think, work for all situations.

Brief Descriptions is:
The entire string is held in a variable, strBBCode. This is declared in a Subroutine. Something similar to that was done for the last code )

change 1) Minor to last code:
Unlike the previous codes, ( which sequentially removed BB Code code tags ( by replacing with "" )), the code tags are replaced by some arbitrary character ( This is simply chosen as any not likely to be used as text in the main initial string https://www.mrexcel.com/forum/excel-questions/867942-visual-basic-applications-new-1-d-array-selected-index-2-d-array-2.html#post4214083 )

change 2) Minor
This itself is not such a major change in the code format, but it facilitates the main change, 3) below. This change is that bulk of the code is within a Function, (Function LongWayOfDoingIt2ReCurseCyClops(__ ) . It is "Called" and needs to be given_..
_.. the string, strBBCode, By Referral to that variable, rather than its By its Value contents
and_..
_.. a Value for the current character position, which initially will be the end ( or length in characters ) position of strBBCode.

But those are not the main changed characteristic to the code.
To recap: All my long string manipulation codes, including this Function, have the general characteristic that they loop backwards in the complete string until a ] is found. An attempt is made then to find a [/ . Once this is found an attempt is made to find a ] and then a [ .
At this point a possible code pair requirement , looking backwards, of ] [/ ] [ is achieved
( Reversing that to the correct order shows that clearly more clearly,
[ _ ] __ [/ _ ],
or
AnyText .
Or
AnyText
_.. etc...)
Having found a code tag pair, a check is made for its validity ( the same matching work, such as, codetext, color, for example ) , before the adjustments are made to the main string. After that , the code then moves on and steps further "back" in search of another pair_..
_.. But just before it does that check, all codes, including this new Function, at the last found [ , do a check to see if in fact the next character after the last found [ is a / , indicating that in fact the assumed start tag, [codeText], was in fact another end tag, [/Codetext_b]. Action is then taken should that be the case.
At this point the codes are very different. The action taken is different
In the previous code, it was assumed that in such an event, the first found "end tag" was a rouge text looking like an end tag , but invalid, and not matched to a start code tag. The first found "end tag" was then ignored, and another search made for a matching start tag to the second found end tag.
This results in an error situation for a valid nested BB Code tags situations.
The new code works therefore much differently.

Main change 3):
In the new code, this point is around lines
[U] [I][color=Green]430

DocAElstein
03-01-2017, 10:28 PM
Final usage of Function
Initial code to Call the Function for the first time. ( The function may Call itself one or more times further )
The Function will not run itself.
It needs to be Called with the initial parameters passed, the main string, strBBCode, along initially with the length of that string as the start point from which to step back.
A routine is needed for that.
Additionally, once the initial Function run , ( which is set off by this routine ) is finished, we will have the original string, strBBCode , returned in a modified form with the replacement character in place of all found code tags. These need to be removed, which can be easily achieved by replacing them with zero length strings.
An example code is given in the next post.








Example Code:
[code]'10 '
Sub TestsBBCodeString() '
20 '
30 Rem 2 Bits needed as Part of Solution
40 '2a) String will need to be got. The variable for it is referred to by changes in any Functions used. The initial length is effectively just the current position stepping back through the total character string
50 ' Some variables: So A variable in VBA is like the Link to the part of proxy site where a few things about the actual Final site is informed about. Tiny is the pointer. Amongst other things it has a link to actually where all the stuff is. Like Dim Str As String means at Str will be stuff like how long the text in that string is as well as a link to the memory where the whole string actually is. So that is like more efficient if you want to get at the length

htt[COLOR=white]ps://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)
https://eileenslounge.com/viewtopic.php?p=320960#p320960 (https://eileenslounge.com/viewtopic.php?p=320960#p320960)
https://eileenslounge.com/viewtopic.php?p=320957#p3209573 (https://eileenslounge.com/viewtopic.php?p=320957#p3209573)
https://eileenslounge.com/viewtopic.php?p=318868#p318868 (https://eileenslounge.com/viewtopic.php?p=318868#p318868)
https://eileenslounge.com/viewtopic.php?p=318311#p318311 (https://eileenslounge.com/viewtopic.php?p=318311#p318311)
https://eileenslounge.com/viewtopic.php?p=318302#p318302 (https://eileenslounge.com/viewtopic.php?p=318302#p318302)
https://eileenslounge.com/viewtopic.php?p=317704#p317704 (https://eileenslounge.com/viewtopic.php?p=317704#p317704)
https://eileenslounge.com/viewtopic.php?p=317704#p317704 (https://eileenslounge.com/viewtopic.php?p=317704#p317704)
https://eileenslounge.com/viewtopic.php?p=317857#p317857 (https://eileenslounge.com/viewtopic.php?p=317857#p317857)
https://eileenslounge.com/viewtopic.php?p=317541#p317541 (https://eileenslounge.com/viewtopic.php?p=317541#p317541)
https://eileenslounge.com/viewtopic.php?p=317520#p317520 (https://eileenslounge.com/viewtopic.php?p=317520#p317520)
https://eileenslounge.com/viewtopic.php?p=317510#p317510 (https://eileenslounge.com/viewtopic.php?p=317510#p317510)
https://eileenslounge.com/viewtopic.php?p=317547#p317547 (https://eileenslounge.com/viewtopic.php?p=317547#p317547)
https://eileenslounge.com/viewtopic.php?p=317573#p317573 (https://eileenslounge.com/viewtopic.php?p=317573#p317573)
https://eileenslounge.com/viewtopic.php?p=317574#p317574 (https://eileenslounge.com/viewtopic.php?p=317574#p317574)
https://eileenslounge.com/viewtopic.php?p=317582#p317582 (https://eileenslounge.com/viewtopic.php?p=317582#p317582)
https://eileenslounge.com/viewtopic.php?p=317583#p317583 (https://eileenslounge.com/viewtopic.php?p=317583#p317583)
https://eileenslounge.com/viewtopic.php?p=317605#p317605 (https://eileenslounge.com/viewtopic.php?p=317605#p317605)
https://eileenslounge.com/viewtopic.php?p=316935#p316935 (https://eileenslounge.com/viewtopic.php?p=316935#p316935)
https://eileenslounge.com/viewtopic.php?p=317030#p317030 (https://eileenslounge.com/viewtopic.php?p=317030#p317030)
https://eileenslounge.com/viewtopic.php?p=317030#p317030 (https://eileenslounge.com/viewtopic.php?p=317030#p317030)
https://eileenslounge.com/viewtopic.php?p=317014#p317014 (https://eileenslounge.com/viewtopic.php?p=317014#p317014)
https://eileenslounge.com/viewtopic.php?p=316940#p316940 (https://eileenslounge.com/viewtopic.php?p=316940#p316940)
https://eileenslounge.com/viewtopic.php?p=316927#p316927 (https://eileenslounge.com/viewtopic.php?p=316927#p316927)
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

DocAElstein
03-01-2017, 10:30 PM
Recursion Function to remove BB Code code tags, described in last two posts





'140 '
Public Function LongWayOfDoingIt2ReCurseCyClops(ByRef strBBCode As String, ByVal BkStt As Long) As String ' I do not actually need any As ______ as nothing is returned, but you never know a string to retuen might be useful later
150 Dim vTemp As Variant ' For Debugs
160 '
170 Rem 1) Main Loop for finding BB code pair String=====================================
180 Dim StpBk As Long
190 For StpBk = BkStt To 1 Step -1 ' Looking for the first ] likely at end of end tag.
200 Let vTemp = Mid(strBBCode, StpBk, 1)
210 If Mid(strBBCode, StpBk, 1) = "]" Then ' we note Position and need to look for a [/ On a recursion call this conditiuon is always met
220 Dim BcrdEEnd As Long: Let BcrdEEnd = StpBk ' Position of possible End Code Tag End
230 Dim posBBCodeTagSrch As Long ' For search through possible valid BBCode Section'_-Loop for Pos tag pair section--
240 For posBBCodeTagSrch = StpBk To 2 Step -1
250 If Mid(strBBCode, posBBCodeTagSrch, 1) = "]" Then Let BcrdEEnd = posBBCodeTagSrch: GoTo NxtCESPosPos ' If we hit another ] then change the stop tag stop character position and start again to see if is a valid BB code section
260 If Mid(strBBCode, posBBCodeTagSrch, 2) = "[/" Then ' Found a stop tag "[/" at posBBCodeTagSrch, so mark..
270 Dim BcrdESt As Long: Let BcrdESt = posBBCodeTagSrch ' ..Position of End Code Tag Start and ..
280 Exit For ' we have an end code tag from a possibly code tag pair section
290 Else 'No luck finding a "[/" start bit of stop tag yet so keep looking Matey
300 End If
310 NxtCESPosPos: Next posBBCodeTagSrch ' trying to find a start [/ pair further back keep looking Matey
320 If posBBCodeTagSrch = 3 Then Exit Function 'case we never found the start of an End Code Tag
330 ' Loop likely at end of start tag ]
340 For posBBCodeTagSrch = BcrdESt - 1 To 1 Step -1 ' Looping furhter back to find a "]" likely of a start code tag but possibly a nested stop tag
350 If Mid(strBBCode, posBBCodeTagSrch, 1) = "]" Then ' possible start from back of "]" likely of a start code tag but possibly a nested stop tag found so....
360 If Mid(strBBCode, posBBCodeTagSrch - 1, 1) = "]" Then GoTo NxtCSSPosPos ' we have a second "]" one back, looking back so this will be caught by next back 1
370 Dim BcrdSEnd As Long: Let BcrdSEnd = posBBCodeTagSrch ' Position of possible Start Code Tag End
380 Dim LTagStLoop As Long ' _- Most Innerloop to find start of start Code Tag
390 For LTagStLoop = posBBCodeTagSrch - 1 To 1 Step -1 ' _- Most inner loop [ likely start of start tag_
400 If Mid(strBBCode, LTagStLoop, 1) = "[" Then
410 Dim BcrdSSt: Let BcrdSSt = LTagStLoop
420 Rem If [/ Then Oh dear time for a "recursion wonk"
430 If Mid(strBBCode, LTagStLoop, 2) = "[/" Then 'Seems like our last attempt at finding a start tag caught a nested end tag
440 'Time to freeze this Function with current end tag info.
450 Call LongWayOfDoingIt2ReCurseCyClops(strBBCode, BcrdSEnd) ' Position of possible Start Code Tag End is actually another end tag end, so give this ] position as the start position and run another copy of the Function. At the start of which the first check should catch the ] and redo the finf´ding of the last tag complete so is a bit ineffecient
460 'Time to unfreeze this Function, and continue where left off having now possibly modified the main string for one or more nested tag pairs, as well as probably catching all but the possible pair that I froze on
470 Let posBBCodeTagSrch = LTagStLoop ' When we went off to the copy of the function our LTagStLoop was at the start of what turned out to be a nested end code tag. That is as good a place as any to strt going further back now to try to find the match for the end tag before the nested one. We will be going throught the lkast nested one, but never mind
480 GoTo NxtCSSPosPos ' unfreeze search for a matching start tag
490 Else ' As soon as we come here we are likely
500 End If ' ready to do the string modification for a found matching pair
510 Let StpBk = BcrdSSt ' - 1 will be done at Next StpBk 'End of Code Tag section search ' I am commiting the cardinal sin of changing the Loop bound variable caount in the main outer step back in character Loop
520 GoTo FkOffCrd ' We leave this For the start Code Tag Start Search and go to Fuk Off Crd:
530 Else
540 End If
550 Next LTagStLoop ' _- End Most inner loop [ likely start of start tag_
560 If LTagStLoop = 1 Then GoTo TheEnd 'I think here we must always be at LTagStLoop = 1 - Case I think we failed to find a start start [ for the complete possible Code Tag section search
570 Else ' Not found a "]" likely of a start code tag but possibly a nested stop tag found
580 End If
590 NxtCSSPosPos: Next posBBCodeTagSrch ' End Loop likely end of start tag ]
600 If posBBCodeTagSrch = 0 Then GoTo TheEnd ' For any outer search failed to find a ] at all or a search for matching start tag that was fruitless
610 FkOffCrd: Rem 3) "I think we come here with a complete set of 4 positions"
620 If BcrdEEnd <> 0 And BcrdESt <> 0 And BcrdSEnd <> 0 And BcrdSSt <> 0 Then 'Just to check'
630 Dim SttBcrd As String, StpBcrd As String ' Start and stop tags as complete strings including [ and ]
640 Dim LenSttBcrd As Long, LenStpBcrd As Long ' Some extra variables for clarity
650 Let LenSttBcrd = BcrdSEnd - BcrdSSt + 1: Let LenStpBcrd = BcrdEEnd - BcrdESt + 1 ' As taypical to get length of anything when start and stop positions are known.. -- (stoppos-startpos+1)
660 Let SttBcrd = Mid(strBBCode, BcrdSSt, LenSttBcrd) ' In String , part from [ , for length (stoppos-startpos+1) ' like |Color=Red| or |b|
670 Let StpBcrd = Mid(strBBCode, BcrdESt, LenStpBcrd) ' like |/Color| |/b|
680 Dim SttWrd As String, StpWrd As String
690 Let StpWrd = Mid(StpBcrd, 3, Len(StpBcrd) - 3) ' like Color from |/Color| - Whole Word, from 3rd Chr , for Length as WholeWord-3
700 Let SttWrd = Mid(SttBcrd, 2, Len(StpWrd)) ' like Color from |Color=Red|
710 If StrComp(StpWrd, SttWrd, vbTextCompare) = 0 And Mid(StpBcrd, 2, 1) = "/" Then ' If UCase(SttWrd) = UCase(StpWrd) And Mid(StpBcrd, 2, 1) = "/" Then 'Ucase allows for differences in cases
720 Mid(strBBCode, BcrdSSt, LenSttBcrd) = String(LenSttBcrd, "|") ' Mid can be used to put in strBBCode , starting from start of tag , for a length space within of the tag = any symbol as many times as that length space
730 Mid(strBBCode, BcrdESt, LenStpBcrd) = String(LenStpBcrd, "|")
740 Else ' ' No manipulationn of string for non matching tag word
750 End If
760 Else 'No manipulation of string for not all 4 [ and ] found. Not sure if I ever come here..
770 End If
780 Else ' Case no "]" found in main strBBCode
790 End If
800 Next StpBk ' Stepping further back in Main Loop for finding first "]"============
810 TheEnd:
820 ' Let LongWayOfDoingIt2ReCurseCyClops = "Return from Function after running" ' Option if I wanted to give a value to be returned from Function. By virtue of the ByRef at signature line I effectively continually apply changes to the variable strBBCode
End Function

DocAElstein
03-02-2017, 08:25 PM
Recursion. A simple Layman explanation

General idea, considering parallel to real life:
Where you work there is a Filing cabinet containing the master copy of a sets of instructions for particular jobs (work sequences). These are your written code routines, ( Sub routines and Functions ).
( These job sequences involves you walking around the company and taking out various actions / tasks in different places ). In general you can only follow one set of instructions at a time. But you can stop them before you are finished, or pause them, and follow a different set of instructions.
Think of those master copies as the routines you write and “see” in the VBA Editor code window. A code module is pseudo a draw in the Filing cabinet.
( ***The analogy falls down a bit when considering recursion due to a poor realisation in the debug step mode ( F8 ) code facility, but this might change due to some changes I have suggested at various Microsoft suggestion giving platforms )

Case 1) The normal working case ( no recursion ). Simple single routine code.
Your boss makes a copy of a set of instructions. He gives them to you. You carry them out. That is your job: You do what the boss says, or rather you follow the written instructions given to you at any time by the boss. Whenever you are given a set of job instructions by the boss, you carry them out, starting from when you are given the instructions. In general you can only do one job ( sequence of instructions ) at a time. In general you are waiting to receive your instructions.
Excel VBA is like the worker. Your worker. You are the boss. If you present Excel VBA with a set of instructions ( a written code in a routine ) , then Excel VBA carries them out. It carries them out from the point of the start line. ( like Sub MyRoutine() etc.. )
In general , Excel is waiting to get , or not doing anything but listening out for, instructions. Something must be done to initiate the initial code run.
In general, at least for our discussions here , VBA can only carry out one routine at a time. But it can stop or pause a routine before it is finished and start another one... that is what happens when other routines are “call”ed from within a routine... as discussed in the next sections:

Case 2) A simple routine call from within a routine
You are doing a set of instructions given to you by the boss.
VBA is in a running routine., following the routine, ( code ), instructions.
The boss gives you a new set of different instructions.
Whilst running a routine, VBA hits a code line which calls another routine or uses, ( calls ) , a routine.
You obey. You stop what you are doing, “freeze” any actions in process, and follow the new set of instructions.
VBA obeys. It stops ( freezes or pauses ) the running of the routine ( code instruction copy ) it was doing, and carries out the new ( code ) instructions.
When you have done all the new instructions, you go back and finish the first job that you were doing, starting where you left off, “unfreezing” any actions stopped when you started the second set of instructions..
When the called routine or function is finished, VBA goes back to the first routine carrying on where it left off. Any variables that may have been “filled” before in the first routine are still there, unfrozen now, with the values previously with which they were filled with.

For the last two simple cases, the Debugging ( F8 ) step mode avaialble in code progression can be helpful to demo what is going on.
It is worth noting that what actually is going on is a bit different:
What actually happens can be thought of as closer to something of this form:
The codes you write are master copies. When a routine begins a copy of that master, including all provisions necessary for a full set of any variables used is made. Once the routine ends, this copy and all variables are erased. ( The analogy to real life: For each start of a job sequence, a copy is made of the master instructions, and this is followed. It is thrown away when the job sequence is completed)
If you step through a code in F8 step mode, the VB Editor will show you progression through the master code copies which you wrote and “see” in the VB Editor code window. That is not what is actually happening. But it is fine to imagine that the originals are the actual copies that are being gone through.
It is worth bearing in mind that copies are made and gone through rather than your written masters. That helps to understand, or rather, helps avoid confusion, when considering the next situation, recursion***


Case 3) Recursion. A routine calls itself
This is not a great deal different from the last case. The word recursion is used to cover the situation of a re occurrence of the same set of instructions or procedure, at a point in code running before the previous instructions or procedure was finished. ( In real life analogy: you are given the same set of instructions written on a new copy before you have finished and following the first set of instructions. - So you pause at the point you are at and start doing the same job again before you have finished doing the last one already started)
Another slightly closer analogy to the programming case of recursion is the following: Imagine that you are doing a set of given instructions, when one of the instructions tells you to make a new copy of the instructions and follow those. In such a case you do as in the previous case: You obey. You stop what you are doing, “freeze” any actions in process, and follow the new set of instructions. When you have done all the new instructions, you go back and finish the first job that you were doing, starting where you left off, “unfreezing” any actions stopped when you started the second set of instructions...
:rolleyes:
You may remark, quite rightly, that you will never finish, as you will endlessly keep making a new set of instructions and begin following the new instructions. In the simple case described, that will indeed occur, ( at least until the stack of instructions you have “frozen” along with any stack of any filled variables, ( newly created for each copy ), hits some “overfull” or “overflow” limit where you are stacking them).
;)
In the practice you would have in your instructions some clause referring to the start of a new set of instructions of the form like: If ..something... Then do it.
Hopefully you have chosen that clause appropriately such that at some point you will skip the step of starting a new set of instructions. Further, hopefully that should occur often enough such that eventually all copies of the instructions are finished.

We can achieve this recursion situation in VBA in various ways. A couple of examples:
_ one simply has a code line within some routine, say Sub x( , ) of the form Call x( , ),
or
_ for the case of some function, Function y( , ) , a code line within that function can be present of the form Var = y( , )
Once again it would be important to have some clause so as to follow that code line only If .. something.

Typical Example:
A very typical working example of such a code is to take some actions to and / or within all the Folders and Sub Folders within some Main start folder.
For such an example you would have two codes:
_ a simple “normal” routine, which might, for example, ask you for the initial main Folder.
_ a recursion routine. The recursion routine would take in a Folder name or Folder path or Folder As Object.
The routine would initially be called from the first simple routine, which would pass the main Folder.
For the Folder taken in by the recursion routine some action on and/ or within that Folder would be taken. This would generally mean taking some action on each Sub Folder within the Folder given. Typically, the last action would be to call the recursion routine, passing this time not the main Folder, but the current Sub Folder, but only If the Sub Folder itself has at least one Sub Folder.
One needs to carefully think through oneself the result of this. In end effect all Folders within the main Folder will be considered.
http://www.excelforum.com/development-testing-forum/1149000-back-up-thread-no-reply-needed-find-and-replace-values-in-all-excel-files-of-directory.html
http://www.excelforum.com/excel-programming-vba-macros/1126751-get-value-function-loop-through-all-files-in-folder-and-its-subfolders.html#post4316662
http://excelpoweruser.blogspot.de/2012/04/looping-through-folders-and-files-in.html?showComment=1477122606199#c216671338370809 3554


Debug ( F8 ) code progression step mode is a bit misleading:
For the recursion case following code progression in debug step ( F8 ) mode can be confusing. This is because during the recurring process you appear to jump around in the main original master copy of the recursion function.
I would suggest one imagines that the following happens instead.
(I would further suggest, that this may be what a more intelligent and more demonstrative debug Editor in a Visual Basic development environment might be developed to do in the future):
Imagine the initial copy of the recursion Function is how you see it whilst stepping through the code in debug step ( F8 ) mode. So imagine that this is , in fact, the first copy of the routine. ( ***Remember I noted that actually, effectively a copy, unseen by us, is actually gone through by VBA )
But.
Consider that the following happens when you carry out the line where the routine calls itself.
At this point a copy of the full recursion routine text is made. If you like , the code line calls into existence a new copy. This is than pasted into the code window below the current routine.
The debug curser then jumps to the start of this new copy of the routine. That new copy of the routine is then stepped through.
Imagine that any variables declared in the new copy routine are given a slightly different shade of color to those with the same name in the first routine. This would help us to remember that they are different independent variable, which just happen to have the same name. ( VBA does not get confused as it only “sees” the variables in the current running copy of the function. Any previous functions and their variables are “frozen” )
When in stepping through this copy, the end is reached , the copy vanishes from the code window, along with any variable that were created and used in it, and the debug cursor then jumps back to the line after the line which called it into existence.
Effectively we are doing the process described in _2) . But to visualise this correctly we need to make a new copy of a routine code text and step through that when a routine calls itself ( Currently when using step mode ( F8 ) debug, the progression appears to go through the same actual procedure. It is following the same instructions contained in the main Master copy of the instructions, but the actual instructions it is following are written on a new copy of the master set of instructions. Similarly any variables used in this copy run are unique to this copy run and “die” at the end of the copy routine run, at which point the copy of the instructions is thrown away )

Alan

DocAElstein
03-19-2017, 10:20 PM
Code for sathishsusa
Post #3
http://www.excelfox.com/forum/showthread.php/2161-Highlight-Overlap-dates?p=10177#post10177


Sub GetsathishsusaStarted()





Sub GetsathishsusaStarted() ' http://www.excelfox.com/forum/showthread.php/2161-Highlight-Overlap-dates?p=10177#post10177
Rem 1) Worksheets Info
Dim WSt As Worksheet 'EP Dim: For Object variables: Address location to a "pointer". That has all the actual memory locations (addresses) of the various property values , and it holds all the instructions what / how to change them , should that be wanted later. That helps to explain what occurs when passing an Object to a Call ed Function or Sub Routine By Val ue. In such an occurrence, VBA actually passes a copy of the pointer. So that has the effect of when you change things like properties on the local variable , then the changes are reflected in changes in the original object. (The copy pointer instructs how to change those values, at the actual address held in that pointer). That would normally be the sort of thing you would expect from passing by Ref erence. But as that copy pointer "dies" after the called routine ends, then any changes to the Addresses of the Object Properties in the local variable will not be reflected in the original pointer. So you cannot actually change the pointer.)
Set WSt = ThisWorkbook.Worksheets("sheet1") ' 'EP Set: Fill or partially Fill: Setting to a Class will involve the use of an extra New at this code line. I will then have an Object referred to as an instance of a Class. At this point I include information on my Pointer Pigeon hole for a distinct distinguishable usage of an Object of the Class. For the case of something such as a Workbook this instancing has already been done, and in addition some values are filled in specific memory locations which are also held as part of the information in the Pigeon Hole Pointer. We will have a different Pointer for each instance. In most excel versions we already have a few instances of Worksheets. Such instances Objects can be further used., - For this a Dim to the class will be necessary, but the New must be omitted at Set. I can assign as many variables that I wish to the same existing instance
Rem 2) Checked Names info
'2a) Arrays of data, value(Boolean) and employee name
Dim RngChk As Range
Set RngChk = WSt.Range("AS8:AT11")
Dim arrChkEmp() As Variant, arrEmp() As Variant ' A simple one line code is used typically wherby the .Value "string values" Property is used to return the cell value from a Range object. These are contained in an Array of Variant types. These can be assigned in VBA to an array of appropriately declared (Dim ed) Member Element types, Variant in this case.
Let arrChkEmp() = RngChk.Resize(, 1).Value ' AS ' Using Resize ing Property applied to a Range object - the Range object resized to (nochange to rows, change to 1 column) effectively returns the first column as a Range object
Let arrEmp() = RngChk.Offset(0, 1).Resize(, 1).Value ' AT ' Before Resize, Offset Property applied to shift enclosed spreadsheet range (no shift in row direction , 1 column shift to the right)
'2b) Build string and Array of Employes checked as True
'2b)(i)
Dim Cnt As Long ' Loop Bound variable Count ' Long is very simple to handle, - final memory "size" type is known (123.456 and 000.001 have same "size" computer memory ) , and so a Address suggestion can be given for the next line when the variable is filled in. '( Long is a Big whole Number limit (-2,147,483,648 to 2,147,483,647) If you need some sort of validation the value should only be within the range of a Byte/Integer otherwise there's no point using anything but Long.--upon/after 32-bit, Integers (Short) need converted internally anyways, so a Long is actually faster. )
Dim strEmp As String ' ' Prepares "Pointer" to a "Blue Print" (or Form, Questionaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular "Value", or ("Values" for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. A String is a a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructiions will tell how to do this. Theoretically a specilal value vbNullString is set to aid in quich checks.. But..http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring-2.html#post44116
Let strEmp = "Overlap dates Between " 'Initial string
'2b(ii)
Dim TrueCnt As Long: Let TrueCnt = 0 ' Count of checked as True employees
For Cnt = 1 To UBound(arrChkEmp(), 1) ' For all employee "rows"
Dim arrChkTrueEmp() As String ' I know the type and am looping to fill in so can choose type
If arrChkEmp(Cnt, 1) = True Then ' Box is checked resulting in Boolean True held in Range object of cell - "...I do not know anything about check boxes. :( ... So I look at TRUE or FALSE value in Array of captured valuees from Range("AS8:AS11")
Let strEmp = strEmp & arrEmp(Cnt, 1) & " and " ' ( '2b)(i) ) add checked names to initial string report for output
Let TrueCnt = TrueCnt + 1 ' Increase count of true checked names ...
ReDim Preserve arrChkTrueEmp(1 To TrueCnt) ' ... Increase array size to accomodate another True name
Let arrChkTrueEmp(TrueCnt) = arrEmp(Cnt, 1) ' Fill next space in Array with next checked as True name
Else
End If
Next Cnt
Let strEmp = Left(strEmp, Len(strEmp) - 5) ' omit last " and "

Rem 3) Main Input data
'3a) Full data range as range object
Dim RngDta As Range
Set RngDta = WSt.Range("B21:E26")
'3b)
Dim arrListNms() As Variant, arrFrm() As Variant, arrTo() As Variant, arrOvrLpDts() As Variant
Let arrListNms() = RngDta.Resize(, 1).Value
Let arrFrm() = RngDta.Offset(0, 1).Resize(, 1).Value2
Let arrTo() = RngDta.Offset(0, 2).Resize(, 1).Value2
Let arrOvrLpDts() = RngDta.Offset(0, 3).Resize(, 1).Value ' RngDta.Offset(0, 3).Resize(, 1).Interior.Color = 255
Rem 4) Main Outer Loop ==============Cnt========= Dim StearEmp As Variant
For Cnt = 1 To UBound(arrListNms(), 1) ' Outer Loop is each name in column B 'Each StearEmp In arrChkTrueEmp()
'4a)
Dim NmeMtch As Variant ' For result of attempt to find next name(Cnt) in arrChkTrueEmp()
Let NmeMtch = Application.Match(arrListNms(Cnt, 1), arrChkTrueEmp(), 0)
If Not IsError(NmeMtch) Then ' This is the case we have found a name I want to check against
Dim CntIn As Long
Rem 5) Inner Loop ------------------CntIn--------
For CntIn = 1 To UBound(arrListNms(), 1)
If arrListNms(Cnt, 1) <> arrListNms(CntIn, 1) Then ' To ignore compare employee with himself
Let NmeMtch = Application.Match(arrListNms(CntIn, 1), arrChkTrueEmp(), 0)
If Not IsError(NmeMtch) Then ' This is the case we have found a name I want to check against
' Now is main part of criteria check
If (arrFrm(Cnt, 1) >= arrFrm(CntIn, 1) And arrFrm(Cnt, 1) <= arrTo(CntIn, 1)) Or (arrTo(Cnt, 1) >= arrFrm(CntIn, 1) And arrTo(Cnt, 1) <= arrTo(CntIn, 1)) Then ' main comdition for match
Let arrOvrLpDts(CntIn, 1) = "Overlap"
Else ' Main overlap condition not met
End If
Else ' Case The Employee name was not one that was checked true to check for Holiday overlap
End If
Else ' case of Checked employee is in Employee Names list
End If
Next CntIn '---End Inner Loop ---------
Else ' Case The outer loop for all names was at a name not to be compared - do nothing and go on to next name in column B
End If ' do nothing and go on to next name in column B at next line
Next Cnt ' --End Main Outer loop ============== ' StearEmp

Rem 6) Loop through arrOvrLpDts() Array to add to report string and mark cell
For Cnt = 1 To UBound(arrOvrLpDts(), 1)
If arrOvrLpDts(Cnt, 1) = "Overlap" Then
Let strEmp = strEmp & vbCrLf & arrListNms(Cnt, 1) & " From " & Format(arrFrm(Cnt, 1), "d" & "-" & "mmm" & "-" & "yyyy") & " To " & Format(arrTo(Cnt, 1), "d" & "-" & "mmm" & "-" & "yyyy") & ""
Let RngDta.Offset(0, 3).Resize(, 1).Item(Cnt).Interior.Color = 255
Else
End If
Next Cnt

Rem 7) Message Box output of report string
MsgBox prompt:="" & strEmp & ""
End Sub

DocAElstein
03-25-2017, 10:11 PM
Notes for
http://www.snb-vba.eu/VBA_Arrays_en.html
http://www.excelfox.com/forum/showthread.php/2157-Re-Defining-multiple-variables-in-VBA?p=10174#post10174 https://www.excelforum.com/the-water-cooler/1174400-would-like-to-know-about-the-forum-experts-gurus-4.html#post4613906



Sub snbsVarTypeTypeName() ' http://www.snb-vba.eu/VBA_Arrays_en.html http://www.excelfox.com/forum/showthread.php/2157-Re-Defining-multiple-variables-in-VBA?p=10174#post10174 https://www.excelforum.com/the-water-cooler/1174400-would-like-to-know-about-the-forum-experts-gurus-4.html#post4613906
a_sn = Array(1, 2, 3, 4)
a_sp = Split("1,2,3,45", ",")
a_sq = Range("A1:F5") ' defaluts to Range("A1:F5").Value ' .Value Property returns a Field ( Arrray ) of Variant Member Elements
Dim a_st As Shape: x = VarType(a_st) ' 9 ( Object )
Rem 2 VarType Constants https://msdn.microsoft.com/en-us/library/office/gg251422.aspx
Dim VrTpe As Long

'2a) Variant Variables: You can determine how the data in a Variant is treated..
Dim Var As Variant: VrTpe = VarType(Var) ' 0 vbEmpty Uninitialized (default)
Dim VarDef: Let VrTpe = VarType(VarDef) ' 0
Let Range("A25:A26").Value2 = "Some text" ' .Value2 gives you the underlying value of the cell (could be empty, string, error, number (double) or boolean) ' .Value gives you the same as .Value2 except if the cell was formatted as currency or date it gives you a VBA currency (which may truncate decimal places) or VBA date.
Let Var = Range("A25:A26").Text ' "Some text" given to Variant attempts to coerce to a String and will fail if the underlying Variant is not coercable to a String type
Let Range("A26").Value = "Some other text" ' .Value gives you the same as .Value2 except if the cell was formatted as currency or date it gives you a VBA currency (which may truncate decimal places) or VBA date.
Let Var = Range("A25:A26").Text ' The data is invalid, a Null is given to Variant
Let VrTpe = VarType(Var) ' 1 Contains no valid data
Dim arrVar(1 To 1) As Variant
Let VrTpe = VarType(arrVar())

'2b) Normal Variables
Dim Intr As Integer: VrTpe = VarType(Intr) ' 2
Dim Lng As Long: VrTpe = VarType(Lng) ' 3
Dim Sngle As Single: VrTpe = VarType(Sngle) ' 4
Dim Dble As Double: VrTpe = VarType(Dble) ' 5


Dim Str As String: VrTpe = VarType(Str) ' 8
Dim Obj As Object: VrTpe = VarType(Obj) ' 9

VrTpe = VarType(a_sn) ' 8204 = 8192 (array) + 12 (Variant)
VrTpe = VarType(a_sp) ' 8200 = 8192 (array) + 8 (String)
VrTpe = VarType(a_sq) ' 8204 = 8192 (array) + 12 (Variant) ' a_sq defaults to a_sq.Value, or rather the = string refs to cells which returns a a Field ( Arrray ) of Variant Member Elements
VrTpe = VarType(a_st) ' 9 (object)
Dim a_bt(1 To 1) As Byte
Let VrTpe = VarType(a_bt()) ' 8209 = 8192 (array) + 17 (Byte)
Dim Rnga_sq As Range: Set Rnga_sq = Range("A1:F5")
Let VrTpe = VarType(Rnga_sq) ' 8204 = 8192 (array) + 12 (Variant (used only for arrays of Variants)) !!!! VarType interprets a Range as an array. ???????
End Sub



Sub TextValueValue2() ' https://fastexcel.wordpress.com/2011/11/30/text-vs-value-vs-value2-slow-text-and-how-to-avoid-it/ http://stackoverflow.com/questions/17359835/what-is-the-difference-between-text-value-and-value2
Set c = Range("A27")
c.Value = 1198.3
c.NumberFormat = "$#,##0_);($#,##0)"
MsgBox c.Value
MsgBox c.Text
MsgBox c.Value2
End Sub
Sub M_snb()
sn = Array(String(300, "p"), String(700, "p"), Space(500))
Dim v
MsgBox Len(sn(0)) & vbLf & Len(sn(1)) & vbLf & Len(sn(2))
End Sub





Using Excel 2007 32 bit

https://msdn.microsoft.com/en-us/library/office/gg251422.aspx






Normal Variable
0vbEmpty Uninitialized





Array Variable
8192Array ( Member elements Empty )





Normal Variable
1If data is invalid, a Null is given to Variant





Array Variable
8193Null





Normal Variable
2Integer

6Currency

11Boolean

Array Variable8192+2=8194

8198

8203

Normal Variable
3Long

7Date

12 -------

Array Variable
8195

8199

8204Variant (used only for arrays of variants)

Normal Variable
4Single

8String

17Byte

Array Variable
8196

8200

8146

Normal Variable
5Double

9Object

36UserDefined

Array Variable
8197

8201

8228

Normal Variable
6Currency





Array Variable
8198





Normal Variable
7Date





Array Variable
8199





Normal Variable
8String





Array Variable
8200





Normal Variable
9Object





Array Variable
8201





Normal Variable
10Error





Array Variable
8202





Normal Variable
11Boolean





Array Variable
8203





Normal Variable
12 -------





Array Variable
8204Variant (used only for arrays of variants)





Normal Variable
17Byte





Array Variable
8209





Normal Variable
36UserDefined





Array Variable
8228




Worksheet: EmptiesVariables

DocAElstein
04-13-2017, 04:28 PM
This is a comment reply I tried to post to Rick Rothstein and Willy Vanhaelen here
https://excelribbon.tips.net/T010768_Shortening_ZIP_Codes.html

Possibly some text annoyed the Firewall?
( Also posted here https://www.excelforum.com/development-testing-forum/1154829-collection-stuff-of-codes-for-other-threads-no-reply-needed-17.html#post4629001
http://www.excelfox.com/forum/showthread.php/2146-%E0%A4%AC%E0%A5%8D%E0%A4%B2%E0%A5%89%E0%A4%97-%E0%A4%95%E0%A5%8B%E0%A4%B6%E0%A4%BF%E0%A4%B6-%E0%A4%95%E0%A4%B0-%E0%A4%B0%E0%A4%B9%E0%A4%BE-%E0%A4%B9%E0%A5%88-%D8%A8%D9%84%D8%A7%DA%AF%D8%B2-%DA%A9%DB%8C-%DA%A9*Trying-Blogs?p=10201#post10201
and in this Text File which is also atttatched https://app.box.com/s/oz2oga0ym6bue2kqf8assy8uq8qdod0e )
_.________________________________________________ _______


Hi Rick,
Thanks very much for popping by. It is really great to hear your “take” on these things. I am continually frustrated that Microsoft, for example, do not give precise information about these things. It appears they are not sure themselves. People like you seem to be the best authorities on this.
To some extent it appears anyone may have an opinion, as no definitive documentation or understanding exists.
I am very glad you seem to think the If({1}, ___ ) is OK: I had been a bit nervous about suggesting it to Willy, as I had not seen it before. But it seemed logical based on all that I had learnt from these sort of things so far.

I have followed your arguments below. You explained very well and I follow your logic and reasoning. Thanks for clarifying a few things.
I came to some general conclusions about what is going on with multi value formula / array analysis and Evaluate. I think I am more or less in agreement with your appraisal. It’s great to hear it. Most people just accept what happens and hack out some of these interesting “coercing” as they often refer to them, as a way to ”get” array analysis to work. Most seem to have no idea how their solutions work.

This is my take, and the reasoning to the
If({1}, ___ )
working as an alternative to the
If(Row(),___ )
( Until recently I only used or had seen the If(Row(), ___ ) or Index( ____ , 0, 0 ) )

I possibly see things slightly the other way around, but probably in end effect the same ...

I was thinking that one of the reasoning’s why CSE is needed is the following:
It seems that single breadth things ( single column or single row arrays or ranges ) , as well as a single range reference works very efficiently due to some mechanism involving an effective help matrix the size of a worksheet which for a single cell reference effectively has that value in the entire cells. For a single breadth range, that matrix is filled in the “other” dimension across or down the effective matrix over the “length” of the range, effectively duplicating the values in the range. This all explains why a single reference like =A1 works very quickly, and also why single breadth things work so quickly, and also explains Implicit intersection which results in a single breadth reference like =A1:A4 or =A1:D1 not giving an error in some cells in a worksheet.
http://www.excelfox.com/forum/showthread.php/2145-Excel-VBA-Interception-and-Implicit-Intersection-and-VLookUp

The problem comes with a multi dimensional range reference like =A1:B2. That will error in any cell. What is required is to somehow do some Controlled Shifting of these effective matrices before the doing for each value effectively a single Evaluation on Enter. Maybe that is why they chose the key combination of Ctrl + Shift + Enter.

In a way, the CSE could be thought of “removing” the direct default connection to the worksheet which results in =A1 giving a result in any cell ( except A1 of course ) and = A1:A2 giving a result in some cells.

My argument then would be that Evaluate does not necessarily do array analysis as such, - It simply does not need the CSE to stop it from erroring. Further my argument is that for any =A1:B2, the array analyses does take place , the values are there, but it messes up in a single spreadsheet cell without CSE.

( Evaluate(“=A1:B2”) works to return an Array as by default Excel holds, I believe such references as Range objects, which then have the default Property of .Value applied in many cases to return the single value or values in an Array as appropriate. That can be proved by setting Evaluate(“=A1:B2”) to a Range object variable. It will return the Range object. Equating Evaluate(“=A1:B2”) to a Variant will result in it defaulting to a value or array of values. )

Coming back to Evaluate and multi value ( array ) analysis. I think Evaluate just evaluates.

In the case under consideration, the range is “there” such as A1:A10 is there in Left(A1:A10,5). This will not error in Evaluate, as it does in all but rows 1 to 10 in a spreadsheet. But Left( ) is not programmed to return an Array. Possibly this is what you are saying by “not array aware”.

But, as you suggest if you embed that text string function within another function that is “array aware”, you can “trick” Left into giving all its available values. My argument there is that once embedded into function that is programmed to do array analysis, then in most cases *** , the following happens:
Excel will evaluate as long and as far and in the dimensions of any arrays “available” . In the case of If(Row(), __ ) or If({1}, __ ) this will mean for our example that it “does” for over the range A1:A10.

The If(Row(), __ ) I have seen many times, first in a Forum answer you gave.
The If({1}, __ ) I guessed, following those arguments should do the same and it did. I had not seen that before but I expect someone else stumbled over it as well a long time before me.


A few post down I suggested what happens when you do like_...

Evaluate("IF(Row(A1:A11),LEFT(A1:A10,5))")

The same reasoning suggest this will be “done” over A1:A11. The last evaluation returns an error, as expected.

The fact that the code below does not produce errors in a second “column” in the Array is explained as follows. Excel holds a single breadth range reference like A1:A10 , as I suggested above , in an effective help matrix extending across or down the “other” dimension
So the returned Array duplicates the results in the second “column”
In a way it is what happens in CSE type 2 array entry in which you extend the area you select ( before adding your formula and doing CSE ) to a spreadsheet area beyond the range of values you are expecting back.


Sub ExtendedAcrossSingleBreadthRefPseudoCSEType2Entry( ) '
Dim Arr() As Variant
Let Arr() = Evaluate("=IF(Row(A1:A10)*Column(A:B),LEFT(A1:A10,5))") ' Run code in Debug, F8 mode, stop at End Sub. - Highlight either Arr - Hit Shift+F9 - OK You will see in Watch window that Arr is a (1 to 10, 1 to 2) array. The "row" values are duplicated across the "columns"
End Sub

https://usefulgyaan.wordpress.com/2013/06/19/avoid-loop-for-range-calculations-evaluate/#comment-739
https://www.mrexcel.com/forum/excel-questions/908760-visual-basic-applications-copy-2-dimensional-array-into-1-dimensional-single-column-2.html#post4375354

_...................................

That is all not a perfect answer, as it does not explain all situations*** such as The T(If(1,____)) stuff _...
https://excelxor.com/2014/09/05/index-returning-an-array-of-values/#comment-2514
_... which recently gave me more hours of frustration than any of your one liners, which I am happy to say I think I mostly understand now.
It was healthy frustration, in that I learned much from you.

Alan

DocAElstein
02-06-2018, 01:55 PM
This is a solution ( from me ) to this excelforum Thread :
https://www.excelforum.com/excel-new-users-basics/1099015-vba-application-inputbox-option-helpfile-helpcontextid.html

It is also required in support of this excelfox Thread :
http://www.excelfox.com/forum/showthread.php/2227-VBA-Input-Pop-up-Boxes-Application-InputBox-Method-versus-VBA-InputBox-Function

Original Question
VBA Application.InputBox Option HelpFile:= HelpContextID:=

Hi,
. I am trying to learn and practice with the .InputBox just now.
. I am getting there with most aspects. But I am struggling to find good explanations of, or rather, examples of actually using the two optional arguments Helpfile and HelpContextID
. Can anyone give me or point me in the direction of a working example / examples using specifically these options, with a brief explanation of what is going on

Thanks
Alan



_
A Bump on the question:


Bump
( on getting these optional things, HelpFile:= _ , HelpContextID:= , to do what ever it is they are supposed to )


Hi
I am getting clued up on the simpler “Pop up User Info getting / giving Window” stuff currently.
I would like to consider them all at their full potential for a better comparison.

So I could do with having an answer to the question that is the main subject of this Thread.
It is a couple of years along the way now – I had just started with computers back then.
I think I may have a better chance now of understanding the Link given to me in post #2 https://www.excelguru.ca/content.php?166-Using-Help-in-Your-Applications
It is clearly not straight forward so I had no chance back then of having the slightest idea what that was all about. At first glance I think I might at least be able to make a start now…

I can’t find any other articles or documentation on this, -
If anyone has any input on this, for example a full working example that they are able to walk me through using, then it could probably save me a lot of time.

Otherwise I will see you here again, in a couple of weeks probably, … when I have sussed it out myself.. :)

Thanks
Alan

P.s.
By the way…. I think I will try initially to look at the HelpFile:= _ , HelpContextID:= _ in conjunction with the InputBox Function ( https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/inputbox-function ) in preference to the Excel Application.InputBox Method ( https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-inputbox-method-excel ) because
_a) I am aware now that the Excel Application.InputBox Method has bugs
( The only difference in the working is that the Excel Application.InputBox Method has an extra last optional argument, Type:= . (One “advantage” of this being that for giving Type:=8 will return an object, which will be the range object of the cells either typed in (as an address), or alternatively selected)……I expect this extra complication is what probably screws things up.. )
_b) I believe the InputBox Function is possibly more fundamental, and I am hoping possibly to further my investigations into a ““more direct API route” with this ( https://www.excelforum.com/excel-programming-vba-macros/1215891-excel-vba-function-method-api-windows-function-user32-dll-alias-declare-library-list.html ) , although it is not clear currently if there is a “more direct API route” for this yet. )
I have also learned and partially myself perfected using string references for referring to range objects as an alternative, and this trend I will be perusing and I expect it to become possibly more trendy to do that. ( It certainly makes code a lot ‘prettier )







Ref
https://stackoverflow.com/questions/13275692/application-inputbox-left-and-top-not-working-in-excel-vba-why/48338078#48338078
http://www.mrexcel.com/forum/excel-questions/447043-left-top-arguments-application-inputbox-method.html
http://www.vbforums.com/showthread.php?617519-RESOLVED-Excel-InputBox-position-works-in-2003-but-not-2007



_.______________________________________---

Last answer before final solution

You obviously did not drink the Microsoft 'Kool Aid', because its' not a bug, its a feature.


Reply _........


Lol.. I really should have thought of that “Feature” idea. I keep trying tell people about the special Forum Software “Features” that excelforum has.
I guess you only get this free drug https://imgur.com/gallery/GjZgOM1 if you are a professional programmer looking to buy some software. I don’t know why but it reminds me of Cresta ( Its Frothy Man https://www.youtube.com/watch?v=tvo2Hddqg3I ), although as I recall the Cresta that I was hooked on as a Kid was pink in color ). Maybe that has some similar secret hidden ingredient to make you like the providers stuff…

I will have to battle through and get the things to the stand that I conceive without a drugged up mind ( well not on Microsoft’s drug anyway ) as “working”. …. Well, … after a fashion …. I think maybe I have in this case … at least working enough to make the rational decision not to use it…
_._____________________



_..........with Final answer in next two posts:

DocAElstein
02-06-2018, 01:59 PM
So.
This whole help file business looks like a very complicated way to do something very simple. Not surprisingly it seems to go wrong a lot and fixing it when it breaks needs a lot of computer programming knowledge.
Maybe I should need to word that differently. Hang on, .. __ let me take a quick swig of my Microsoft 'Kool Aid' __ then I will begin.. _...
If I may, just to avoid confusion. I will use the term “Bugg y feature” to refer to what rational thinking says is a Bug and what when drugged up on Microsoft 'Kool Aid' appears as a neat feature.

Microsoft Help Text aka “Help” “Feature” and “Buggery features”
Aka , as applied to this Thread..
What is HelpFile:= HelpContextID:= about
It is impossible for me ( or anyone I expect ) to guarantee to walk you through a working demo of getting the “Pop up” box optional argument parameters of HelpFile:= HelpContextID:= to do what ever it is that they are supposed to do.
The reason for this is that the “Buggering Features” are too many and varied.
Anyway_....Microsoft have a “Help” system, ( Sometimes referred to loosely as “Help” ). Crudely this could be considered as an alternative to writing some explanatory notes in a media such as a text file, or Word document or as in a supplied user manual.
It has the interesting “feature” that in order to master it and use it you will become, or need to be, at a fairly confident level or programming and general computer knowledge. You may need constant access through the internet to get help and advise onto how to maintain the system , that is to say make it continually work, as changes , such as Microsoft updates, will result on additional things needing to be done as time goes on. One of the major “feature” therefore is its Volatility…. And / or it often does not work
A useful tip I have learnt when looking for general information on this Microsoft help through the internet is to include extra terms such as “problem” or “not working”. Without these terms it proved almost impossible to get ay information on the Theme, but with those terms, a great deal of information was obtained allowing for possibility of using up many hours of time in the many interesting actions that may likely to be needed in order to make the Help work, and or repair the damage done to many other things in the initial attempts. These include adding and removing security updates, and manipulating registries and the such both manually and with computer programs calling up many API codes.

Here we go,
Help text Window Feature and “Buggary features”
Most things “Help” or of the help nature in Microsoft uses similar looking Windows. When, for example you is in the VB Editor ( Alt+F11 from Excel spreadsheet ) Window looking at code, you can highlight a word in the code, hit F1, and then such a Help Window comes up
HelpApplicationHelp.JPG : https://imgur.com/ZAXUHmW
So there could be some thinking behind the “Microsoft Help” as a (bad) attempt to bring it all together in some organised way.
.chm Files ( getting them to work/open)
These are the files used as the “raw data” in whatever hidden software takes these files and uses them in some process to get those help windows up. They contain some sort of compressed data of coding written in some variation of the HTML language.
It is likely you may have some .chm files, as the Microsoft Help Text aka “Help” is likely have been used / integrated into some software that you may have on your computer
You may find some ( in Vista and Win 7 ) if you click on the bottom left Microsoft sign and then type in _ chm _ in the small search box.
Here are some also that I made or found earlier https://app.box.com/s/bx2pkvtemsppscz60rd6f430wm89c6fj https://app.box.com/s/varm2k1ojlwwtemnefuhhnym1d84bcxs

It is impossible for me to guarantee to walk you through a working demo of getting the HelpFile:= HelpContextID:= to do what ever it is that they are supposed to do. One of the “Buggering Features” that may prevent getting a successful use of Help is that security updates from Microsoft may intentionally or unintentionally prevent a .chm file from operating as initially intended.
Solutions to this problem range from one extreme to the other.
_ One extreme is major heart surgery to registry files, along with a possible need for application of additional software.
or
_ If you are lucky some of the following may be all you need to ensure that a .chm file will work as it should:
Try out a .chm first( sometimes you need to have done this to make other workarounds work fter you find out that it doesn’t work )
After finding or downloading such a file, navigate to it in its folder , and make a note of its path and file name. ( In the Microsoft Explorer window you may be able to copy the path to the clipboard
chmFolderPath.JPG : https://imgur.com/5Si2HIq )
So for that example shown you need to make a note of the following path and file name ( remember the extra \between the two ) :
G:\Excel0202015Jan2016\ExcelForum\UserForm\sampleh elp.chm _ ‘This is the sort of Help File string that you will need
Now try either of the following:
_(i) Double click on the file in the Window Explorer window
or
_(ii) Run this code ( change the Help File string to suit what you have as a .chm File )

Sub HelpGetItUp()
Application.Help HelpFile:="G:\Excel0202015Jan2016\ExcelForum\UserForm\sampleh elp.chm"
End Sub
As a result of doing either of those a Help Window Thingy may or may not come up. If it does come up, it may give an error , that is to say something in the largest window to the effect of one or more things. Here a couple, with workarounds:

Buggery Internet Error Feature 1:

i Navigation to the webpage was canceled.
__ What you can try:
__ .- Retype the address.

Workaround:
If that error is obtained it may mean that some form of blocking has been done by some sort of security measure. If this has happened an extra option will now be seen towards the bottom of the general settings in the Properties Window which you see by right clicking on the file in the Windows Explorer Window and selecting _ Properties
chmUnblock.JPG : https://imgur.com/ObMrbOy
Hit _ Unblock.
After doing this, the (i) or (ii) should result in a normal looking Help type Window.
Note:
_ It may initially be necessary to make the attempt of the (i) or (ii) , or otherwise you may not see the option _ Unblock.
_ Strangely it is sometimes necessary to have done the above workaround in order to avoid other problems later. So it is sometimes advisable to try and get this Buggery Internet Error Feature. One way to achieve this is to upload and then download the .chm file to a trusted file sharing site such as box.net ( https://account.box.com/signup/n/personal#rw1w0 )

Buggery Internet Error Feature 2:
A similar “Internet Error” window may show:
ThisProgramCanNotDisplayTheWebPage.JPG https://imgur.com/NduujoY
i This Program Can Not Display The Web Page

Workaraound: WARNING: Do this at your risk. You are messing with dangerous stuff
via left bottom Microsoft symbol_ regedit.exe_ HKEY_LOCAL_MACHINE
regeditHKEY_LOCAL_MACHINE.JPG https://imgur.com/MHAggqH
_ SOFTWARE --- Microsoft
SOFTWAREMicrosoft.JPG https://imgur.com/n5TnD1b
HTML --- 1.x --- right click mouse _ Neu --- Key
HTMLHelp1_xNewKey.JPG https://imgur.com/z7QnvCV
Name the new folder that appears as _ ItssRestrictions
ItssRestrictions.JPG https://imgur.com/nDyE9tL
right click mouse _ Neu --- DWORD (32-bit) Value
Name the new folder that appears as _ MaxAllowedZone
Double click on that to get an edit Window
EditDWORD32bitValue.JPG https://imgur.com/07AAqu1
Give a value of _ 4

Refresh your computer somehow
(**** Edit: 25Jan 2018: .. another possible Registry modification reported, but have not tried it as have not needed it yet )

3_ Buggery Features 3
See next post for another way to get over the “Help” thing usually not working

_.________________
Back not to the original Thread question:

_ Application.InputBox(Prompt:= , Title:= , Default:= , Left:= , Top:=, HelpFile:= , HelpContextID:= , Type:= ) Method
Coming back to the Theme of this Thread.
As noted , to avoid the extra complication for now of the “Application.InputBox Buggery features” , I am considering a slightly different thing
__ InputBox(Prompt:= , Title:= , Default:= , Left:= , Top:=, HelpFile:= , Context:= )
__( Note the slight syntax difference between Context:= and HelpContextID:= ) Function
One main part of the Thread question ( what are those two options supposed to do ) can now be [Solved]:
Two possible ways to “launch” a .chm help file where discussed ( (i) and (ii) )
A third way (iii) is possible.:- Many of the “Pop up User Info getting / giving Window” stuff have the option to allow a button to “launch such a file” …
Typically the Options are like
The main option:
_ HelpFile:= _________ --- _______ The full path and file name of the .chm file
A second option:
_ HelpContextID:= or Context:= _ --- _A number that takes you to a particular part or section of the main text

_ For InputBox _ it appears the Context:= is not optional.
_ For Applcation.InputBox and for Application.Help _ it appears that HelpContextID:= is optional. (But it is not too clear with the case of Applcation.InputBox due to the additional “ Application.InputBox Buggery features”)
_ For InputBox it appears that no Button for help must be specified: it will appear if HelpFile:= and Context:= are given. ( There is no option to add buttons anyway here )
_ For MsgBox the button option (buttons:=vbMsgBoxHelpButton ) must be given or the Help Button will not appear. ( But if the (buttons:=vbMsgBoxHelpButton is not given and the helpfile:= and context:= are given and valid, then the code line will not error )
_ For Applcation.InputBox it would appear that one of the “Buggery features” is that no Help Button comes up. ( But then..Nothing to do with the Help seems to work for Excel 2007+ with Applcation.InputBox _ – That is a “feature” of it .. “Bugger me feature”


The next post will attempt to make a .chm file. But will also have to tackle possible further “Buggery features”


Ref:=
InputBox ( Prompt:= , title:= , default:= , xpos:= , ypos:= , helpfile:= , context:= ) ) ' If helpfile is provided, context must also be provided. Button comes then automatically.
MsgBox ( prompt:= , buttons:= , title:= , helpfile:= , context:= ) ' If helpfile is provided, context must also be provided . _ For the required Button buttons:=vbMsgBoxHelpButton must be given
Application.InputBox ( Prompt:= , Title:= , Default:= , Left:= , Top:= , HelpFile:= , HelpContextID:= , Type:= ) ' “Buggery Features”: In Excel 2007 + Left:= , Top:= , HelpFile:= , HelpContextID:= can be anything and are ignored
Application.Help HelpFile:= , HelpContextID:= ' , HelpContextID:= is optional

https://stackoverflow.com/questions/11438634/opening-a-chm-file-produces-navigation-to-the-webpage-was-canceled
https://msdn.microsoft.com/en-us/library/aa445082(v=vs.60).aspx
https://www.youtube.com/watch?v=1gdGpnCCFWM
**** http://www.winfaq.de/faq_html/Content/tip2000/onlinefaq.php?h=tip2026.htm
https://powerspreadsheets.com/excel-vba-inputbox/

DocAElstein
02-06-2018, 02:01 PM
Create a Help Project. Aka make a .chm file that probably won't work
Part 2 A walkthrough example
Part 2a) Getting a .chm file that might come up by double clicking on it or via Application.Help HelpFile:=MyCodeX.chm

_3_ Buggery Features 3 / Workaround ( To understanding WTF Microsoft HTML Help Workshop is ) :
This is just one way that on average lead to the most success of getting a final working .chm
Instead of starting from scratch, I found I had a better chance of producing a final .chm if I started with one that worked and went backwards.
Unfortunately this is characteristic of many things Microsoft. You need to have a working answer to or a working solution to get there ? A "chicken and egg" situation. So I have done my best to give a working solution on which to build / modify.

In a way I am not really using the Microsoft HTML Help Workshop as it is intended. I guess the Idea is that you can make , edit and organise all the files you need to create a final .chm with the Microsoft HTML Help Workshop Development Environment. Sounds simple but I could not find any decent documentation or learning material. In most of the You tube videos the author seemed confused and surprised half the time as to what was actually going on


To start with you need to have a working .chm.

DocAElstein
02-06-2018, 02:02 PM
Create a Help Project. Aka make a .chm file that probably won’t work
Part 2 A walkthrough example
Part 2b) Getting a .chm file that might launch from the help argument options in InputBox Function

_4_ Buggery Feature Context-Sensitive Help ( InputBox Function )
A special form Of Cursor Lock:= was used when the Microsoft data base xxxxs developed a few things:
Cursor Lock:= Load of dis coordinated Bollox aka Another mess and it does not work ever not even from the start but don’t tell anyone maybe they won’t notice.
From the last post we see that for _ InputBox Function ' If helpfile:= is given , then context must also be provided. ( This is not the case for Application.Help, - the HelpContextID can be omitted. )
But possibly someone that should have taken that into consideration forgot about or did not know that . Oh dear.
In fact, frequently a problem arises ( not just in the case of the InputBox when calling up a help Window ) : You may get an unexpected error, or rather an error message , something of the form
___ HH_HELP_CONTEXT called without a [MAP] section
HH_HELP_CONTEXTcalledwithoutaMAPsection.JPG https://imgur.com/8NOQW95
( The code may go on further never the less , after hitting OK, or even in some case it will move on whilst the Message box is still showing, but the Help Window you wanted will not be shown.
The following workaround may get around this problem.

Workaround: ( Patch up the .hhp file )
From this point I am not quite sure what it is that I am doing, but it appears that some “directions” are missing. These are necessary to satisfy one of the standard Windows programs ( API ddl stuff: http://www.eileenslounge.com/viewtopic.php?f=18&t=28885 ) which is called into use , for example, by the the context:= argument parameter, which in the case of the InputBox Function is not optional once the helpfile:= is given.

## The main project file ( the file with the .hhp extension ) can be opened with a text editor such as Notepad++. Or at least if you do that something is displayed which you can edit as if it was normal text. What you see there is similar to what you see in the left hand window of the HTML Help Workshop window after you have a created/ compiled project:
One way to get to this is in the Windows File explorer Window select and right click mouse to get the option to Edit with Notepad++
RightClickOnhhpFileOpenWithNotepadPlusPlus.JPG https://imgur.com/7AOgfiQ

By modifying the .hhc project File in Notepad, saving that, and then opening the hhc project file in Microsoft HTML Workshop, and finally compiling will result in the changes reflected in the final .chm file

These following changes, taking the current working example as example will illustrate the added information which appears to add the “missing directions”
Part of the initial File looks something like this, here in this example showing two HTML Files:

[FILES]
INDEXPAGE.htm
_1X40LL8V5.htm
Somewhere under that must be added something to give finally in place of that above , the following final text shown below

[FILES]
INDEXPAGE.htm
_1X40LL8V5.htm

[ALIAS]
AnyWord = INDEXPAGE.htm
AnotherF___ingWord = _1X40LL8V5.htm
[MAP]
#define AnotherF___ingWord 2
#define AnyWord 42

After doing this, the file must be opened in Microsoft HTML Help Workshop and compiled to produce a new .chm
Usually then I got success in calling up a help window from a code line including both of the two options
of
HelpFile:=
and
the context:= or HelpContextID:=.

Exactly what is going on there is anyone’s guess, or those that know won’t tell, maybe as they forgot to get the whole thing co coordinated correctly from the start. For some unknown reason a constant variable must first be associated with a File, ( That is the AliAS stuff ), after which a number can be given to that variable.
I got this info from various reported ways to fix various bugs, ( those were not directly related to anything to do with the InputBox Function ), so I expect there are some integrate internal coding reasons for having to do this bodge ( workaround )

Note also interestingly, that in both the case _... of the
_ InputBox __ ‘ including HelpFile:=, and context:=
and the
_ Application.Help __ ‘ including the optional HelpContextID:= argument
_... as long as valid sections are given in the hhc “text” section, then the code will not error if a non existent Context number is given. In this case no help window comes up.
If a valid ( existent ) context number is given then… if you are lucky… it works finally !!!!
_...____

So I got it to work., finally…. :)
I went through worked examples following all the stuff that I have tried to explain in the last few posts..
Then when I run a code like this:

Sub UpDogsBollox()
' Application.Help HelpFile:="G:\Excel0202015Jan2016\ExcelForum\UserForm\HTML Workshop\chmFillesProjectFiles\Jan21\AnyFileName.c hm", HelpContextID:=2
Dim strReturned As String
Let strReturned = InputBox(Prompt:="Hello Help World. Help", Title:="Alan Help", Default:="Bollox", xpos:=100, ypos:=100, HelpFile:="G:\Excel0202015Jan2016\ExcelForum\UserForm\HTML Workshop\chmFillesProjectFiles\Jan21\AnyFileName.c hm", Context:=2)
End Sub
This is what happens:
First an InputBox pops up,
and then
if you select the Help Button, ….. then a help Window comes up :)
HelpGetUpBollox.JPG https://imgur.com/KdKOYWr







Conclusions:
I think am happy to mark this thread as [Solved].
I have got as far as making the_..
HelpFile:= HelpContextID:=
( or rather the InputBox Function which works
HelpFile:= Context:= )
_..options in the typical “simple Pop up user interface message box / input box” to work, after a fashion, to do whatever it is that they should do.
What they should do is at least clear now:, ( Obvious to some maybe.. but no documentation says this clearly … ): The typical _ helpfile / context _ optional arguments should cause an extra button to appear which when Hitting should launch a Window which is part of the “integrated Microsoft Help” thingy.
I have gone where probably not many have in recent years, and that is to get working examples.
I’ve got far enough to realise that the “integrated Microsoft Help” thingy might have been somebody’s career making pet idea for a while and seemed a good idea at the time. In the mean time it is a mess and usually does not work.

It would probably be better to go back to writing notes on the back of a Beer mat
:) ( And don’t bother with the drink Microsoft 'Kool Aid'. – drink something better. I can recommend some good dark German Bier )

[Solved]
Alan
P.s.
( Any comments or further inputs would be very welcome, Thanks )







Ref
https://msdn.microsoft.com/en-us/library/windows/desktop/ms524279(v=vs.85).aspx
https://www.codeguru.com/cpp/w-p/help/html/article.php/c6513/Starting-with-HTML-Help.htm
https://support.microsoft.com/de-de/help/189453/how-to-prepare-html-help-files-for-context-sensitive-help
http://www.help-info.de/en/Help_Info_HTMLHelp/hh_context-id.htm



Some general notes:

Files:
hhp _ is a project File. The big thing that you usually will want to create as / with _ File --- New _ with HTML Help Workshop or other software. This will somehow contain or at least “manage” somehow the following 3 file types

“data” type files, which are used in
hhc _ is a Help table of contents, usually just 1 I think
hhk _ is a Help index, usually just one I think
htm _ are fairly standard HTML file thingies. If you read any good introduction article, book or watch a good introductory You tube video then you will soon get the general idea
https://www.youtube.com/watch?v=1gLhs5QycAE&list=PL1CD6F7E289625976
These HTML files contain as main part the bulk of all the text and other stuff you actually want to read. If you are lucky then you might find that simply double clicking on them will “bring them up” as normal looking stuff to read. This probably will come up in your internet browser: Most browsers I expect recognise these types of files, and you can also probably get them up manually if you copy the whole string path and file name and then paste it into the URL bar of your browser ( URL Bar = the place where you usually see the long _ https://www.goog………………. _ – In place of that paste in the _ G:\Excel0202015Jan2016\Ex……………\Part2.htm )

Modifying Files:
The hhp file opens in Notepad ++ and shows some text. ## This was useful in order to modify to add those missing [ALIAS] and [MAP] bits
All other files can be opened and modified in a text editor such as Notepad or Notepad ++

Actually making/ modifying a “Project”:
I’m buggered if I could actually work out how to use the HTML Help Workshop Development Window in the efficient way that I expect it should be.
I expect the idea is that you move around and modify the HTML Files and some how do all the index and contents automatically. But god knows how.

This is how I actually got the stuff working…
Way a) manipulate all files with text editors… mostly !!
The hhc and hhk files ( List index contents stuff ) look similar and have to stay similar, at least as far as how the HTML files they reference is concerned.
You open them up with a text editor, preferably both at the same time, and make sure that the HTML Files that they reference exist.
Changehhkhhchtm.JPG https://imgur.com/0gMOk8J
Once you have done that, then you don’t actually have to “load the HTML Files”… when you make a new project… these files, and / or the hhp file and / or the complied .chm “ know where they are and what to do with them.
The HTML Files you then modify manually by opening them up in a text document .. or even in Word it seems possible !!

Default Topic Index Page Title Page
The hhc File and the bit of the hhp File that opens in a Notepad ++ and the left margin window must all reference the same Default topic=, but god knows what that is – it seems to be some HTML file that must also exist
So you need to change 4 things simultaneously,
_ 1 hhc File in a text document
_ 2 the bit of the hhp File that opens in a Notepad ++
_ 3 !! and for this you have to be in the Microsoft HTML Help Workshop Development Environment .. modify the left margin window bit .. Project .. [OPTIONS] …..
_ 4 the name of the HTML file
IndexPage_1_2_3_4.JPG https://imgur.com/ztE5ZES

Way b) In the Microsoft HTML Help Workshop Development Environment
Select either the Contents or Index tab ( to right of the Project tab ) , and double click on the bit you want to modify. The corresponding HTML File comes up the main big window and you can work on it similarly to as if you had opened with a text program such as Notepad or Notepad++

DocAElstein
02-25-2018, 03:24 PM
VBA to automate Send and Automatically Sending of E-Mails and Workbooks.


Learn Material

In support of this Thread
http://www.excelfox.com/forum/showthread.php/2233-Urgent-support-needed-Multiple-emails-multiple-Excel-workbooks-at-once



Available stuff on the internet
I downloaded about 40 YouTube videos, ( TheElvesAndTheShoemakerAndEmailUsingVBA.JPG : https://imgur.com/rPNV8Kd ) and found an endless amount of Blogs and other technical support and documentation. I doubt it is possible to review all the Blogs and other technical support and documentation as there is just too much.
I narrowed down the You tube tutorials to a list approximately in order of how good I found them.
Its on a scale of 1 to 10 , 1 as very useful and 10 as not very useful. Above 10 gives an approximation of how far away I estimate they are in informing / educating as needed to allow somebody to successfully produce and understand a working code

Here is the current list:

I will update it from time to time


_1 ) Way 1) Use the CDO (Collaboration Data Objects ) object library available in VBA.


_1b ** VBA A2Z : Email Automation using VBA. Use GMAIL, Yahoo, Microsoft etc. : https://www.youtube.com/watch?v=nj8mU3ecwsM
_1a ** Dinesh Kumar Takyar : How to send email using Gmail via Excel VBA : https://www.youtube.com/watch?v=pFl7W8d7d4M
_2a DontFretBrett : Send Email From Excel Using VBA & Gmail : https://www.youtube.com/watch?v=cOhupIT0rNA
_4 ** FREE VBA TIPS : gmail vba automation | smtp error fix - gmail via Excel automation - vbatip#31 : https://www.youtube.com/watch?v=Z4aHONly9UQ
_5 Computergaga : Email Workbook as an Attachment - Excel VBA- : https://www.youtube.com/watch?v=ibjNwZqOZnY
_6 GuideMe ShowMy Testie : How to send an automated email using VBScript : https://www.youtube.com/watch?v=H4nnPxnCIbI
_7 Office Academy : Send Email from Gmail using Excel VBA- Modified (with Code Explanation) https://www.youtube.com/watch?v=KIH_FjpPZyg
_8 FREE VBA TIPS How to send email using gmail via Excel VBA _ 100% working _ sample attached - vbatip#30 https://www.youtube.com/watch?v=cJ3tQTjRTHM
_10 Excel VBA Excel VBA _ Total Automation of Sending eMails https://www.youtube.com/watch?v=xGFI3H60yXY&t=9s


Note these ** give details about the security settings required in gmail
gmail security settings
For the purposes of my Excel VBA Email investigations I use two Email accounts: My main German Telekom ( t-online.de ) account. I had no problems with this and more or less everything worked the first time.
I also made specifically a gmail account. I wanted to start from scratch with this to investigate the reported typical security issues that typically seem to prevent the codes initially working. I report my experience with these issues here:
Gmail account code testing
The Way 1), using the CDO object library , was completed and was working successfully with my main German Telekom ( t-online.de ) account.
The I made an account, ExcelVBAExp@gmail.com ( https://support.google.com/mail/answer/56256?hl=en https://accounts.google.com/SignUp ) . The confirmed account was then given as
___ excelvbaexp@gmail.com
I edited code such:
_ changed the username to __ excelvbaexp@gmail.com
_ changed the password to that I had given and confirmed when setting up the account
_ changed the server name to __ smtp.gmail.com
_ used the user server port of 465 ( for my Telekom addressee 456 or 25 seemed to be OK )
_ changed _ .To = Doc.AElstein@t-online.de _ to _ .To = excelvbaexp@gmail.com
I ran code _ Sub PetrasDailyProWay1_COM_Way() _ and it worked first time!!
Here were some of my settings:
excelvbaexpInitialSettings.JPG https://imgur.com/NkvDbvB
LoggedInMy 1 Account 2 SignInSecurity LessSecureApps 3 ON.JPG https://imgur.com/IZEHuGs

I changed the setting from the last screenshot to less Secure Apps OFF. I then got this error when running code code _ Sub PetrasDailyProWay1_COM_Way()
Runtime Error 2147220975 (80040211) LessSecureAppsOFF.JPG : https://imgur.com/ddmNJ2E



Laufzeitfehler '-2147220975 (80040211)':

Die Nachricht konnte nicht an den SMTP-Server gesendet werden. Der Transportfehlercode lautet 0x80040217. Die Serverantwort lautet not available


Runtime Error '-2147220975 (80040211)':

The message could not be sent to the SMTP server. The transport error code is 0x80040217. The server response is not available

After switching back to Less Secure Apps ON , the code worked.
LessSecureAppsONfrommWarning.JPG : https://imgur.com/TW2Z7XQ
LessSecureAppsONfromWarning2.JPG https://imgur.com/TW2Z7XQ
Note: I had to refresh and log in , Log out etc.. a few times, before it let me slide the switch to ON








_2 ) Way 2)
Office Software.. one of ‘em
Microsoft Outlook …….
I currently do not think it is possible to use this for a “stand alone” way to use Excel VBA to automate Email activity. This is reflected in no rating under 10 or anywhere near. This is not necessarily reflecting the quality of the videos. This is simply my estimation of how relevant they are to a “stand alone” way to use Excel VBA to automate Email activity. I guess I might think differently if I were more familiar with actually using the Outlook software alone for personal management and Emails etc..


40 Wise Owl Excel VBA Introduction Part 29.1 Creating Outlook Emails https://www.youtube.com/watch?v=f8s-jY9y220&t=1813s
129 How to send Email through Outlook at Specific Tme https://www.youtube.com/watch?v=Oa4uDulciQ0
140 Jie Jenn Send Email From Outlook In Excel _ Excel VBA Tutorial https://www.youtube.com/watch?v=3m2THsOZWjg
154 YourProgrammingNetwork Excel 2010 VBA Tutorial 61 Sending Emails https://www.youtube.com/watch?v=iuLb3glfZdk
156 YourProgrammingNetwork Excel 2010 VBA Tutorial 62 - Sending Emails with attachements https://www.youtube.com/watch?v=mOjxfCNnu-U
158 Excel # 348 Serienmail mit mehreren Anhängen über Outlook versenden VBA https://www.youtube.com/watch?v=i-gvQQ0749Y
159 Dr. Gerard Verschuuren Outlook API VBA Can Send Emails from Excel through Outlook or Shell https://www.youtube.com/watch?v=UTzq6-UrmP8&t=10s
160 Send E Mail in VBA Excel through Microsoft Outlook (Video 1 of 4) https://www.youtube.com/watch?v=OwLgf7jebAs
162 Alex C Send Mass E Mail to Distribution List with Outlook and Excel (Video 2 of 4) https://www.youtube.com/watch?v=i_uJNMJVW1k
163 Alex C Send Personalized Mass E Mail to Distrubiton List with Outlook and Excel (Video 3 of 4) https://www.youtube.com/watch?v=sIQLedQPrPs
164 Send Outlook E mail from VBA Excel with HTML Tags (Video 4 of 4) https://www.youtube.com/watch?v=wuoV47SQeKU
171 Excel macro to send bulk emails using Outlook https://www.youtube.com/watch?v=uW8gjf3lB88
190 Excel VBA _ Total Automation of Sending eMails https://www.youtube.com/watch?v=xGFI3H60yXY
255 Send an outlook email with attachments via vbscript https://www.youtube.com/watch?v=nmr283CD_-M&t=93s
260 Excel Macro to Send Email from Outlook with attachment https://www.youtube.com/watch?v=7gy2oRQdGf0
386 Send Invoice as an Email Attachment VBA https://www.youtube.com/watch?v=QsmWVSIW77Y
403 Using Dates with Excel VBA to Automate Email Reminders https://www.youtube.com/watch?v=x2_y0_KDaN0
409 Send email from excel using VBA w3 https://www.youtube.com/watch?v=V3Uc38y4
430 SparksEdge ToExcel SparksEdge_ How to send an Emails using Excel and VBA https://www.youtube.com/watch?v=5hJbSngqpP8
445 Kiran Manchekar Send email using excel macro VBA Tutorial https://www.youtube.com/watch?v=GVopzYXsnqY
700 Jie Jenn How to automatically CC people when you send an email _Outlook Tutorial https://www.youtube.com/watch?v=BGMcsQ89JUk



_._______________________________

Videos from Dinesh Kumar Takyar


CDO way
4 Dinesh Kumar Takyar Aug 28, 2014 CDO How to send email using Gmail via Excel VBA https://www.youtube.com/watch?v=pFl7W8d7d4M&t=16s

Excel VBA – Outlook way
4 Dinesh Kumar Takyar Nov 16, 2012 How to use automation to send ms outlook mail using Excel VBA https://www.youtube.com/watch?v=XSR4gmBuqiE&t=161s
5 Dinesh Kumar Takyar Nov 21, 2014 Automate Excel To PDF & Send PDF Document As Mail Attachment https://www.youtube.com/watch?v=XEBr12uxG2I&t=105s
7 Dinesh Kumar Takyar Jul 3, 2014 Automatically send email to users queries in Excel with VBA https://www.youtube.com/watch?v=N1DMPct5cVA&t=214s
11 Dinesh Kumar Takyar Apr 28, 2014 How to send email reminder automatically from Excel Worksheet using VBA https://www.youtube.com/watch?v=Em4RCvsAV7s
9 Dinesh Kumar Takyar Feb 23, 2018 How to send Email through Outlook at Specific Tme https://www.youtube.com/watch?v=Oa4uDulciQ0&feature=youtu.be
12 Dinesh Kumar Takyar Oct 1, 2014 Using Dates with Excel VBA to Automate Email Reminders https://www.youtube.com/watch?v=x2_y0_KDaN0&t=19s






_.________________________________________________ ______________________-




Here are some other YouTube Videos were some information may be gleaned, but I have not fully reviewed them. They are generally not so useful as the previous ones.




Email Worksheet Via Outlook in Excel _ Excel VBA Tutorial-2jrA-IscKq4
How to Email Your Current Workbook in Excel VBA-0xnk-kjbrpo
Out API VBA Can Send Emails from Excel through Outlook or Shell-UTzq6-UrmP8




Automated email report of excel data-5miDjW6pp5c
Automatically Display Worksheets of Specific User-FPJBVa5i8ec
how to send email in outlook _ vba-i-USyj-iPnY
send birthday emails in powerpoint using VBA-1jFJ35ZPR_A
Serien-Email mit Access, VBA und Outlook versenden-LfDUie6Mlzg
VBA How send email in Access-c41EJLd7HOQ
VBA macro to send a email to one of a list of emails-A-SWhq4GJs4

DocAElstein
03-01-2018, 03:37 PM
German Telecom ( Deutsch Telekom ( Freemail t-online.de ) ) Copy Paste HTML code work around

I had a problem for a long time when copying manually via the clipboard from Microsoft Word ( or from most other sources ) into my main Email Internet tab Browser Program , t-online.de ( German Telekom Free mail).
The problem started suddenly, close to the time that some update/ changes were made to the Program a few years ago.
The problem was that usually most formatting was lost, and only simple plain b/w text came into the browser.
Previously, most formatting , such as text color, text fonts , test size etc. were maintained such that the final E mail main body as seen and sent, looked very similar to as the prepared message in the Word document. This maintaining of format was / is still the case when pasting manually into gmail and many other places. ( This conversion to simple b/w is usually only seen when pasting into very simple basic text reply windows which supported no formatting )
Formatedtext.JPG ; https://imgur.com/A9Sq5Y1 PastedInGermanEMail https://imgur.com/CZRH5jj
19771978
( Here is the same after pasting into gmail: PastedIn gmail.Jpg https://imgur.com/CzqCJ7y )



I noticed the issue in a different situation, and was able to do a simple workaround that spread some light on the issue.
This post gives the background to the situation.
The next post explains the workaround. ( The workaround by passes pasting into the German Email Reply/Editor Window, but the sent and received Email does not suffer from the problem of loss of formatting ).

The issue in a different situation..- The situation
I answered a Forum question here recently, ( http://www.excelfox.com/forum/showthread.php/2233-Urgent-support-needed-Multiple-emails-multiple-Excel-workbooks-at-once ), and a spin off was a further insight into the issue.
The thread concerned automating sending of an Email with attachments using ( Excel ) VBA.
The successful solution involved sending directly to any Email the complete protocols, messages, HTML code string etc.. etc.. that any Email program, such as Email Internet tab Browser Program , t-online.de , would in end effect “send” out along the internet. ( The final solution was not dependent on having any Email Program available or open. )

The VBA Program to send Email solution:
It was a completely independent “stand alone” solution: Part of the program “ took in “ the main body / main content of the message, that is to say what a user would normally manually type in and/ or paste in. ( As seen in the above screenshots )
( This main body is what I personally might prepare, for convenience, ( and for purposes of having a back up ) , in a Word document and then copy and paste manually across. That copied across would then be sent , and the Word document is then effectively my back up copy of the sent message )

Supplying the main Email message body to the code:
This main body can be supplied to/ given within the code
either as…….
_ a simple text string, like pseudo __ = “ Hello,” & vbCrLf & “ this is my message. “ __ , which would give a final message received like

Hello,
This is my message
That text can also in code typically be supplied in a single String type variable in a typical code part like:
Dim strText As String
_ Let strText = "Hello," & vbCrLf & " this is my message"


Dim strText As String
_ Let strText = "Hello," & vbCrLf & " this is my message"
or………

_ alternatively it could be given as HTML code supplied similarly in a long string variable. That string variable would contain a long string of all the HTML necessary to create text, table, pictures and all possible formatting. That HTML type code can usually be read by most “internet type” or general computer communication type software such as to be able to show a complete formatted page or pages just as one might see in an internet web site or a large Microsoft Word document containing all sorts of formatting including tables, pictures, etc.. etc.. ( I chose to use this second HTML string giving way). This sort of coding is the most common language, at least up until recent years, in computer communication generally.
( By the way htm, HTML ,XHTML, html are more or less the same – it is all to do with coding which mostly consists of ” tag pairs” made with pointy brackets https://www.youtube.com/watch?v=1gLhs5QycAE&list=PL1CD6F7E289625976 )
Making/ writing the .htm code string
If I was a fluent computer HTML expert then I could just write out the htm equivalent of the message with formatting that I wanted to send by Email. I am not, and I don’t need to be: There are many ways to get the code, such as free converters on the internet which give the code if you paste in what you finally want into a window. ( All software I have tried have not suffered from loosing the format when I paste in to their window )
But something even more convenient is available as standard with Microsoft Word:
A simple practical solution was found to be to take advantage of the possibility of saving a normal Word ( file, normally saved with the extension .docx ) , with a file extension of .htm
SaveAs Word.JPG Save As Word doc to htm.JPG https://imgur.com/h7XFAQX https://imgur.com/vhRE9CC
This somehow saves the document primarily in some version of HTML coding language. ( I have no idea what it normally does with the .docx extension – probably a trade secret ). A small amount of coding was then all that was necessary to convert that .htm file into a single text string of the type required for the Email sending code with the option of supplying the main body in HTML format. ( That coding is a line like, pseudo _ strText = GetTheFileAsATextStreamandReadItAll_ )

HTML is one of the main languages used in internet communication, and most internet browsers and Email programs use this. ( In the case of the first simple test string option, ( = “ Hello,” & vbCrLf & “ this is my message. “ ) , that given text string would probably be converted initially by some software into HTML coding before being further used . ( Hence it is more efficient to use the htm option in the first place )

The long HTML string is rather difficult to “see” in its single string form as it is literally an extremely long sting text with pointy bracket HTML code. To a first approximation, this long string of information forms the bulk of what is actually “sent down the internet line”.
No programmer could ever examine easily such a long string of coding. The coding is therefore organised neatly with things like the _ vbCrLf _ used in simple text strings to give a new line.
Because of this last point, if you open such a HTML file with a simple text editor then you see the coding neatly laid out.
For example, this is a screen shot of a simple Word document, which I made and then saved as .htm:
ProMessageTelekom.JPG : https://imgur.com/zn3BGWj
1974
“ProMessageTelekom.docx” : https://app.box.com/s/pumcahipuhjbl59ka7lb3qv8i682kcwc
“ProMessageTelekom.htm” : https://app.box.com/s/vfz0y102bikl9hrka6dlgqyotlrttlpi
If I right click on the .htm File in the explorer window, then I can choose to open this file in a simple text editor , ( rather than by using Word, which may be the default, - but note always: You might find that by default it opens on your Internet browser, - that is because , as noted, that browser software has as its main job reading HTML coding and converting it into the text , pictures, tables etc. that you can “see” )
OpenProMessageHTMLWithTextEditor.JPG : https://imgur.com/4zev9Kv
1975
Opening the file in a text editor will give you ( towards the end ) the actual coding relevant specifically to “making” that seen text. The relevant part is in between the “pointy bracket code tag pair” named _ div class=WordSection1 ___ /div __ That section is all that I am interested in: All the other stuff is I expect a lot of stuff specific to a Word Document or maybe even some other complicated stuff. I don’t know
ProMessageHTMLInTextEditor.JPG : https://imgur.com/eTUd17q
1976

Last part of HTML code for File “ProMessageTelekom.htm” :
See here:
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10525#post10525




Using code instead of Email Window to send Email ( with attachments )
The codes for doing this are described from here: http://www.excelfox.com/forum/showthread.php/2233-Urgent-support-needed-Multiple-emails-multiple-Excel-workbooks-at-once?p=10518#post10518
The end result is , simplified, as follows:
The .htm file is “sent” by the code along the internet line as a HTML code string
rather than
pasting into the Email Editor and hitting the send button manually

The German Telekom Email Editor / Email Program is not used by this particular code . ( that step is effectively bypassed). So, the issue of the format loss occurring when pasting into the German Telekom Email Editor / Email Program is not present

However: The received Email in German Telekom suffered a similar problem.
Using the same Word file example again:
This was the File used to produce the HTML code string to send
ProMessageTelekom.JPG : https://imgur.com/zn3BGWj
This came on as expected in most places, for example in gmail:
ProMessageArrivedAt gmail UsingCodeToSend.jpg : ProMessageTelekom.JPG : : https://imgur.com/u57kRD7



But.…
.. The same sent to a German Telekom t-onlone.de address came on with a similar format loss problem to that experienced when pasting into the German Telekom Email Editor / Email Program
ProMessageRecievedAT tOnLinede UsingCodeToSend.JPG : https://imgur.com/h4wJVXd



_.______________________



So that this post was in way of an introduction.

In the next post is the bit relevant to the issue with pasting into a German Telekom Email Window..

DocAElstein
03-01-2018, 09:48 PM
Solution ( work arounds ) to the issue with pasting into a German Telekom Email Window..


To recap from last Post….
I had a problem for a long time when copying manually via the clipboard from Microsoft Word ( or from most other sources ) into my main Email Internet tab Browser Program , t-online.de ( German Telekom Free mail).
The problem started suddenly, close to the time that some update/ changes were made to the Program a few years ago.
The problem was that usually most formatting was lost, and only simple plain b/w text came into the browser.
Previously, most formatting , such as text color, text fonts , test size etc. were maintained such that the final E mail main body as seen and sent, looked very similar to as the prepared message in the Word document. This maintaining of format was / is still the case when pasting manually into gmail and many other places. ( This conversion to simple b/w is usually only seen when pasting into very simple basic text reply windows which supported no formatting )
Formatedtext.JPG ; https://imgur.com/A9Sq5Y1 PastedInGermanEMail https://imgur.com/CZRH5jj
( Here is the same after pasting into gmail: PastedIn gmail.Jpg https://imgur.com/CzqCJ7y )


Some thing similar was experienced when I recently wrote a compute program to directly send Emails:

This was the File used to produce the HTML code string to send
ProMessageTelekom.JPG : https://imgur.com/zn3BGWj
This came on as expected in most places, for example in gmail:
ProMessageArrivedAt gmail UsingCodeToSend.jpg : ProMessageTelekom.JPG : https://imgur.com/u57kRD7

But.…
.. The same sent to a German Telekom t-onlone.de address came on with a similar format loss problem to that experienced when pasting into the German Telekom Email Editor / Email Program
ProMessageRecievedAT tOnLinede UsingCodeToSend.JPG : https://imgur.com/h4wJVXd


_._______________________-


I looked at and compared a lot of different sent HTML strings , and examined what came into different places.
In other words I messed around empirically with the HTML string, and then took a look at how that effected the formatting actually seen in the final received and viewed Email.
I do not really understand HTML programming ( or anything much with computing for that matter ) so I do not know the significance of what I noticed.
However I was able to consistently ensure that the correct format was received , that is to say , the received Email looked very similar to as it had in the prepared Word document.

I went on to write an additional part , ( an extra Function ) which made the necessary changes to the HTML code string just before the final sending. This consistently resulted in the correctly looking Email being received.

Once again using the same example:
This was my prepared Word document, saved in .htm extension, and used in my code to produce the long string of HTML code text to send as an Email:
ProMessageTelekom.JPG : https://imgur.com/zn3BGWj

With the modified code, the received Email now looks like this:
ProMessageRecievedAT tOnLinede UsingModifiedCodeToSend.JPG : https://imgur.com/UuPdyOR

_._________

The code modification:
The existing code:
Part of the existing coding is a Function
( http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10517#post10517 )
This uses the Word .htm file to produce the single ling string of HTML coding.
The final result is for that Function to return that string in the variable MyLengthyStreaming
Effectively the signature line of the Function defines / declares that variable thus:
Pubic Function MyLengthyStreaming() As String
VBA indeed holds a variable of name MyLengthyStreaming of String type whilst that Function code is running

That code line is then effectively, pseudo
xxxxDimxxxxxxx MyLengthyStreamingxx As String
In place of the normal “filling” of a variable by pseudo_...
xxstrvariablex = xxxxxxx
_.. we do something similar by
xxstrvariablex = MyLengthyStreaming()

The result is that the Main code execution pauses at this part MyLengthyStreaming() , whilst the function code , Function MyLengthyStreaming( ) is carried out. Then the main code resumes once that function is Ended. Generally the final result of the Function will be to fill the variable MyLengthyStreaming within that function. So then the complete execution of that code line _..
xxstrvariablex[/color = MyLengthyStreaming()
_.. will return the filled value of MyLengthyStreaming into strvariable.

The above is a typical progressing when a main code Calls a function code.


Modification / additional Function
The strategy now is simply to modify the final string in MyLengthyStreaming within the function.
For convenience I have done this in another, second function,
Pubic Function MyLenghtyDiesScreaming_Telekom(ByVal MyLengfyScream As String) As String

This Function is called from within the first function, in this extra code line which is the main modification to the existing codes:
Let MyLengthyStreaming = MyLenghtyDiesScreaming_Telekom(MyLengthyStreaming)
This function differs slightly from the first function in that it contains an argument passed in the brackets ( _ )

Effectively the purpose of the function code is to use the value in MyLengthyStreaming before returning that modified value back into MyLengthyStreaming. So it modifies the HTML string in MyLengthyStreaming

Once again , this is one typical way that a function is used

The Function I have called Function MyLenghtyDiesScreaming_Telekom
It has the signature line of
Pubic Function MyLenghtyDiesScreaming_Telekom(ByVal MyLengfyScream As String) As String
Effectively the signature line Dim’s MyLenghtyDiesScreaming_Telekom as a String variable and MyLenghtyDiesScreaming_Telekom can be used as such in this function code. Assigning a variable to this in a main code will cause the value held by VBA in the variable MyLenghtyDiesScreaming_Telekom at that point to be out in the assigned variable, but first the main code will be paused at this “Ccalling” code line whilst the function code is carried out. So we have the chance to do something in the function to fill that variable, MyLenghtyDiesScreaming_Telekom . We can take one or more things in, in the ( __ ) to use . In this case we want to take a string in and then return it modified , hence the last code line is simply
MyLenghtyDiesScreaming_Telekom = MyLengfyScream


_.______

What is the main modification
After a lot of experimenting it appeared that the modification which mostly gave the desired end results were to do some simple exchanging of ' and "

As example a HTML part such as this_..

<p class=MsoNormalCxSpMiddle><span style=[color=Blue]'font-size:24.0pt;line-height:115%;
font-family:GungsuhChe;color:#0070C0'>W24 <span class=SpellE>GungsuhChe</span></span><span
style='font-size:24.0pt;line-height:115%;font-family: "Franklin Gothic Heavy", "sans-serif";
mso-fareast-font-family:Batang;color:#0070C0'> <o:p></o:p></span></p>

_..will be modified to this_..

<p class=MsoNormalCxSpMiddle><span style="font-size:24.0pt;line-height:115%;
font-family:GungsuhChe;color:#0070C0">W24 <span class=SpellE>GungsuhChe</span></span><span
style="font-size:24.0pt;line-height:115%;font-family: 'Franklin Gothic Heavy', 'sans-serif';
mso-fareast-font-family:Batang;color:#0070C0"> <o:p></o:p></span></p>



How is the main modification done
In VBA coding there are many ways to achieve the required modification. My final way is probably not the most efficient. But it is fairly easy to follow through, - I have ‘commented it extensively.


The modified first function and additional function is here:


Notes:
_1: The modification seemed to have no effect on the end result when the modified HTML string was sent in place of the original for other Email Program recipients other than German Telecom ( Deutsch Telekom ( Freemail t-online.de ) ), so I have not bothered to add anything to select use of the function only in the German Telekom recipient case. But this might be a more efficient development to do that later.
_2: I added a few bits to the function to remove the larger parts of the HTML coding that appeared not to be relevant to the main body text.

_.__________

Here is the modified initial function and the new second function:
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10528#post10528

DocAElstein
03-25-2018, 07:31 PM
Some Notes to help Distinguish between these Two Worksheet embedded Button types:
ActiveX Control ; and
Form Control

In these Threads:


I am asking for help in understanding and getting a simple Button in a Worksheet. That Button should set of a VBA macro code

This post is just some notes to clarify the two things that I am talking about…

Currently there are two ways to do this:
Form Control
ActiveX Control

For the case of a simple Button to start a macro, they appear to work fairly similarly. There is a lot of stuff “behind” them that I know nothing about. I would like to get familiar with them, and if possible both types up and running before deciding which / where to use.

So this post is just to make clear what I am talking about and give the basic characteristics and features of the two types, just so we all know what we are talking about , ( at least in terms of the very initial introduction of using them initially.

So…

Just to be clear what I am talking about..
The button things that I am talking about
I am talking about the things you “insert” into a worksheet like this…

Excel 2007+ (‘_- Find the hidden Development Ribbon Tab, then select the tools controls icon to get both of them ! :-)
https://support.office.com/en-us/article/Assign-a-macro-to-a-Form-or-a-Control-button-d58edd7d-cb04-4964-bead-9c72c843a283#ID0EAABAAA=Windows
http://www.jkp-ads.com/Articles/controls01.asp
Excel 2007+ Form and ActivX Control buttons.jpg https://imgur.com/x2OxFvX
https://app.box.com/s/st84weg49tjgj25x49iib8h1mv9gb7k4
2022

( To get you back to 2003 Menu stuff should you be familiar and prefer : https://www.youtube.com/results?search_query=ubitmenu https://chandoo.org/wp/2009/10/19/excel-2003-toolbar-in-2007/ … and/ or then…. )
Excel 1997-2003
(‘_- a) Select the View Tab then select either or both of the controls Tool Bars , http://www.jkp-ads.com/Articles/controls01.asp https://imgur.com/VLv2uvM Excel 2003 Form and ActiveX Control buttons.jpg https://app.box.com/s/me97qpwtmzybm42ed8z876q19bd801o9
2020

or b) Select the View Tab then select the Visual Basic tool bar, from which you can select the tools controls icon to get the ActiveX controls Tool bar :-) https://imgur.com/AqHDBBH http://www.jkp-ads.com/Articles/controls01.asp?AllComments=True#25922 Excel 2003 ActiveX Control button from VB Tool bar.jpg https://app.box.com/s/l40n0ktm5d8uzrswe3czyae2xby60hqa
2021
_.................

General Stuff about them, what they are..
Form controls ( not to be confused with UserForms ) were an original part of Excel so allowed you to customise the Worksheet a bit. Probably one reason they were kept is to allow for backward compatibility. ( In the meantime they are probably kept as the alternative ActiveX stuff goes wrong a lot )

ActiveX was some attempt by Microsoft to combine some other stuff which was itself an attempt to combine or allow communication through a communicating object which then they tried a bit later to extend to embedding that object in stuff… ActiveX controls refer to a specific way of implementing the earlier technologies, and no one has any idea anymore exactly how it all works or what links still exist when they “run” , so it is no surprise it has turned into a mess where things go wrong and no one is quite sure why.
ActiveX things have a strong reputation of breaking themselves or breaking other stuff, ( maybe because of all the attempt at linking stuff that they are supposed to do? ) so they can really mess things up basically. Viruses for example can slip through all the links or routes that get set up and which no one remembers anything about. ( I keep seeing myself that they suddenly do not work for no apparent reason. I have not managed to get ActiveX controls Buttons to work at all yet on a couple of computers with Excel 2003 ). It sounds like you need to be a bit of a computer expert in a lot of stuff outside Excel if you use ActiveX controls Command Buttons because of all the damage they may cause.
ActiveX controls
It would appear that the word ActiveX could almost apply to anything. The ActiveX control things here might be described as the ones optimised for internet, Internet Explorer, but which also work, as I am using them, in Microsoft Office
( ActiveX controls don’t work on a Mac: I expect that is because they are attempting to link a lot of Microsoft stuff, so it would be a mammoth task to get them working outside a Microsoft environment, especially as they don’t work very well in the Microsoft environment either , not that is of interest to me )

Codes associated with / assigned to a “Worksheet Button”
Form Control code
To see the code already assigned to an Excel Form control button you select the option to assign it which you get in a menu when you click right mouse when the mouse cursor is in it. Then it will highlight the current Sub assigned it.
ActiveX Control code
( Right clicking will have the same effect as left click, that is to say activate/ press the button.
You need to get into “design mode”, then the right click will get you the code…..)
To see the code with a Command button ActiveX control you first have to select the Design mode icon which is next to the Controls icon in:
( For Excel 2007+ the Ribbon from the Visual Basic Development Tab ( https://imgur.com/MqVC6jB ); Excel 2007+ Form and ActivX Control buttons and ActiveX Design Mode .JPG https://app.box.com/s/3udml4bnnn07um7lgeg0uwpuczj8m0pm
2022
and
For Excel 2003 the Visual Basic Development Tool Bar or ActiveX controls Tool bar ( https://imgur.com/yR2491F ). Excel 2003 ActiveX Control button from VB Tool bar.JPG https://app.box.com/s/l40n0ktm5d8uzrswe3czyae2xby60hqa
2021
Once in Design Mode, a right click when the cursor is in a ActiveX controls Command Button will give you the option to view the code , and on selecting that option, the appropriate worksheet code module will pop up. )

Text on the Button:
ActiveX control
For an ActiveX control button you also need to do that select the Design mode icon step to be able to edit the text on the ActiveX button ( which you then do by a right click on the button followed by selecting Properties option. Then you can edit the Caption Property from the Property Window that comes up ) , and it appears that the text can only be in a single line. It would appear that the caption is a property of an under Object within the Worksheet Object ( https://imgur.com/MqVC6jB ).
Form control
For a Form controls Command Button to change the text you right click on the button then select the text and you can change it and also , it appears have the text on multiple lines

Codes sorts behind them:
ActiveX control
ActiveX controls Command Buttons are a sort of “Eventy Clickies** thingy”, so the code has to go in the Worksheet Code module of the Worksheet in which it is. So a specific ActiveX controls Command Button is a VBA Object thingy. It gets called a Private Sub when you add / Insert it. You can change it to Public Sub , and that does not seem to make much difference
( ** So you can have other codes with an ActiveX control, reacting on additional things such as passing over a Button.
CommandButtonClickies.JPG : https://imgur.com/uxkIpZS
2023

For the Form control you just have the click ……. )
Form control
I don’t quite know what sort of a thing a Form controls Command Button is. It is a pseudo a single event ( click ) Thing: You assign one code to it. You can do that, for example, by clicking on the right mouse when the mouse cursor is on it, followed by selecting the option to assign a macro after which the pop up macro assign window should pop up. It appears to me###, based on my experiments, that the code can go anywhere and can be Private Sub or Public Sub, ( although you will not get it offered as one to choose from in the pop up macro assign window, if you make it a Private Sub. ( ###This observation from me contradicts some stuff I have read which says the codes are always written in normal modules… well they ain’t by me .. and no ill effects yet )











Ref:

https://www.excelforum.com/excel-programming-vba-macros/1209246-when-i-create-vba-code-via-code-generation-for-1-event-fine-but-2-crash-boom.html#post4787311
https://www.excelforum.com/excel-programming-vba-macros/1209246-when-i-create-vba-code-via-code-generation-for-1-event-fine-but-2-crash-boom-3.html#post4789873

DocAElstein
03-26-2018, 03:06 PM
Some additional notes on things broken ActiveX controls..
These are just some additional notes in support of other Forum Threads on the Theme of things “broken by / with ActiveX controls”
http://www.excelfox.com/forum/showthread.php/2242-Excel-2003-ActiveX-controls-embedded-in-worksheet-not-working-then-can%E2%80%99t-even-insert-them
http://www.excelfox.com/forum/showthread.php/2241-VBA-Worksheet-Buttons-Form-controls-Command-Buttons-verses-ActiveX-controls-Command-Buttons
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10586#post10586




List of, and search of Updates on Computer:
Often one hears that updates can cause problems with things “Activia X y controlly” . This Post considers ways to automate seeing what you have and checking for particular ones reported to have given problems with ActiveX controls…….
( Actually what we are doing here is to get a list of updates on a computer and / or search through/ for them. So this post may be of general interest when looking for any updates on a computer ).
Old black box command Dosy Window looking at Files stuff
Getting a window up that looks like an old black screened computer up and typing simple old computer type commands seems to be what one often uses when delving into these sort of things, so that is a good start point.. ( I think this window thing is possibly similar to the console Window thingy in Visual Basic https://www.mrexcel.com/forum/general-excel-discussion-other-questions/547261-error-goto-only-works-once.html#post4357648 )
Get it up
From Hans here: http://www.eileenslounge.com/viewtop...=28682#p222044
http://www.eileenslounge.com/viewtopic.php?f=18&t=28682#p222044

_ Press _ Windows key + r _ to activate the Run dialog
Windows+r.JPG : https://imgur.com/1KI8nok
2024

_ Type in box bar _ cmd _ if not already shown
cmdInBoxBar.JPG : https://imgur.com/L9saGzj
2025

_ Press _ Ctrl+Shift+Enter _ to start an "elevated" command prompt.
ElevatedCommandPrompt.JPG : https://imgur.com/W1p6frJ
2026

Get a list of Updates in a text file
Note: In the following steps you need to type a few things in exactly as given. I have sometimes experienced problems with characters not working and / or pasting in not working. But usually one or a combination of the following will work
_ (i) If you are lucky you can type all characters.
_ (ii) Copy text from here and paste in using _ Ctrl+v
_ (iii) Copy text from here and past in using _ option given when clicking right mouse
_ To get a text file produced, for example on your desktop, type in a single code line something like these examples , using a file path to suit you:

wmic qfe get hotfixid > C:\Users\Elston\Desktop\UpdatesOnVistaAspire4810TZ G25thMarch.txt
wmic qfe get hotfixid > C:\Users\Alan\Desktop\UpdatesAcerMartinWin7Pro64Bi t26thMarch.txt

It may take a few seconds, and then you should see a text file appear ( in this case it appeared on my desktop because I put that path in ) looking something like this : https://imgur.com/9Ze2FY6
Here is the first part of the text file on one computer.


HotFixID
{EF8CD7FC-438D-49E3-A2C7-201052D9F2EF}
{8D2CDFAB-0079-43CC-A289-2F7A67F0A4DE}
{98D8F490-1F42-4F29-A59B-BF96D23A11BA}
{B730F010-3FCF-4E80-8A5A-C1DBEC0CF55A}
{B73E5AF4-40C6-4EA9-8F57-CFA70CC72BD6}
{BF11577A-6876-45AA-86C9-2BA4CFB8B019}
{E359D786-B101-4545-B8AB-8652323CF3CA}
{F4139440-5426-4C6F-909B-F71CEB1071B1}
{B2FAD7E1-67F9-435D-98BD-A77DBF4E1381}
{0CC8FAD2-05D8-4A0A-9E5C-2CDACFF86996}
{0EF0D4FB-BB23-4515-AAEA-1240AC2DA525}
{800D1A82-D1B0-4ED4-89B4-C666B570ABA5}
{8D2CDFAB-0079-43CC-A289-2F7A67F0A4DE}
{98D8F490-1F42-4F29-A59B-BF96D23A11BA}
{BF11577A-6876-45AA-86C9-2BA4CFB8B019}
{E359D786-B101-4545-B8AB-8652323CF3CA}
{F4139440-5426-4C6F-909B-F71CEB1071B1}
{B73E5AF4-40C6-4EA9-8F57-CFA70CC72BD6}
{D6C976E4-E88C-4048-9A6B-39400D2933C7}
{FC8EA2A2-65A3-366E-A687-5B63943A800F}
{6F8500D2-A80F-3347-9081-B41E71C8592B}
{AC76BA86-7AD7-0000-2550-7A8C40011010}
{FC8EA2A2-65A3-366E-A687-5B63943A800F}
{D758F295-2DE9-4A95-B857-B18BF52A26B2}
{E94DDFCD-6D84-40A4-B5DF-24AE25761924}
KB971513
KB971512
KB982861
982861
KB960362
942567
KB971514
KB2761494
KB2079403
KB2117917
KB2141007

Here is the uploaded text file obtained from a couple of my computers
“UpdatesOnVistaAspire4810TZG25thMarch.txt” : https://app.box.com/s/z90o8yj7iz0188yci34mu7gahe2tfhce
“UpdatesAcerMartinWin7Pro64Bit26thMarch.txt” : https://app.box.com/s/8m96l0e7yh1wcb15y06eaaz6a7vtjzgd

It would be nice to automate that . I Don’t know how :(
Never mind. In any case you should now be able to get a list

Search the list for specific updates updates
A few ways…
( A way without using the text file )
_ use the command like : _ wmic qfe get hotfixid | find "KB1234567"
If KB1234567 is installed, you'll see KB1234567 on the next line, otherwise it'll remain blank. : http://www.eileenslounge.com/viewtopic.php?f=18&t=28682#p222044
https://imgur.com/9Ze2FY6

( Ways using the text file )
_ Knacker your eyes looking through the text file
_ You may be able to do a simple search with your text editor. Using Notepad I can get a search from the following options from the top of the open editor window of something like __
--- Bearbeiten --- Suchen
or
---- Edit --- Search
or
using the shortcut key combination __ Ctrl+f
You then have a search window in which you can type in what you want to find
Note however: I think there are sometime some strange characters that are not always visible to you, and then a search may fail as it won’t make a perfect match possibly. I am not too sure exactly what I mean there, but others have told me some quirky things can happen such that that text search fails…
The next way can help over come that ###

_ It can easily be automated to search the text file using VBA. I prefer to do this mainly as it is less likely for me to make a mistake, but also as I have found some strange characters coming in to dirty/corrupt the string of the update, and the search can be done for a match on part of the string which will help offset the problem of missing a match due to the string corruption ###
Here is a simple code.
Sub CheqUpDates()
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10586#post10586
You input the Updates that you want to search for with one or more spaces in between, and you can type in just part of the character string. All matches will be returned in a string in a message box, and also that string is available to be copied from the immediate window.

DocAElstein
04-14-2018, 03:26 PM
Code to make Day list from Excel File and show in Pop up Word .htm File.
MakeTagList Button , Sub MakeTagList()
This post gives some Overview notes for later reference to help clarify some other more detailed excelfox Threads.

MakeTagList Button. Briefly, overview:
The code Sub MakeTagList(), primarily does two things:
_ makes a simple text file with the important details from a Daily Diet Protocol
DailyTextFileForEmailAttatchment.JPG : https://imgur.com/MqEmlDF
2053

_ makes a long string of HTML coding which if written to a text file, (but with the usually given .txt extension replaced with .htm ), is recognised by Microsoft Word which can open it in a form which looks similar to a normal Word doc
That Word File is opened temporarily to show a pretty table form of the important details from a Daily Diet Protocol:
TemporaryWordPopUp.JPG : https://imgur.com/ZFhsdaQ
2054

_.___________



_ makes a simple text file with the important details from a Daily Diet Protocol
arrNuts()
The start point is that an array is made of used food products from daily pro, arrNuts()
arrNuts() is the = Items() array from a Dictionary. So it is a one dimension array starting at arrNuts(0). Each Element is a row from the from the Daily Excel Diet Protocol File, “ProAktuellex8600x2.xlsm”. It is built up from a line like pseudo

Key:=ProRow with Entry in C column, Item:=Array(FoodProduct in 1st Column A , amount eaten from 3rd Column C , Kcal total in 9th column I , Fett , Eiweiß …. Etc.
( The Key is not used currently )

Rem 5 Text File
A text file is made from the array with a pipe, _ | _ , as separator like from:
arrNuts(0)(0) & “|” & arrNuts(0)(1) & “|” & arrNuts(0)(2) ……..etc..
arrNuts(1)(0) & “|” & arrNuts(1)(1) & “|” & arrNuts(1)(2) ……..etc..
arrNuts(2)(0) & …..etc..
The final text file is stored in the same Folder as most of the files to do with daily protocols, that is to say, the currently used main Folder . It is given a name something of the form pseudo
“MonatsUebersichtAnhang " & Date in format like "mmmm yyyy" & “.txt”
As example for any day in April, 2018, it will be like
“MonatsUebersichtAnhang April 2018.txt”
The main purpose of this text file is to have a file that can be attached to an Email which at the receiving end can then be for recording and using the important daily nutrition values in a graphic
I use the standard VBA type code lines for this , pseudo like
Open C: \ __ \ _ \ ¬¬¬-___“MonatsUebersichtAnhang April 2018.txt” For __ As __
_.___________

_ makes a long string of HTML coding which if written to a text file, (but with the usually given .txt extension replaced with .htm ), is recognised by Microsoft Word and can opens it in a form which looks similar to a normal Word doc
Rem 6 .htm Word Template File
An empty or almost empty .htm Word file, “DailyProtable.htm “ , ( which should be in the main currently used Folder already , - ( download from box if necessary ) ) is converted into a single very long String variable , TotalFile
I use the fairly standard VBA way often used to get this long string from a .txt file. It seems to work equally well for a .htm file

Rem 6 get Template File as long HTML string . Template file is an almost empty Word .htm file.
Dim FileNum As Long: Let FileNum = FreeFile(1) ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
Dim PathAndFileName As String, TotalFile As String
Let PathAndFileName = ThisWorkbook.Path & "\" & "DailyProtable.htm" ' Template file never changes
Open PathAndFileName For Binary As #FileNum 'Open Route to data. Binary is a fundemental type data input...
TotalFile = Space(LOF(FileNum)) '....and wot recives it hs to be a string of exactly the right length
Get #FileNum, , TotalFile
Close #FileNum
Rem 7 modify main body text section of the template file

Rem 7
Things start getting a bit complicated now. It may help at this point to give a summary of the overall goal:
The final aim of this code and the associated code usually done just after, Sub PetrasDailyProWay1_COM_Way() , is to get a pretty summary table in a HTML code such as it is in a form that can be used for two things:
_ Temporarily in a Word .htm file which is opened temporarily to show the current stand of a finished or almost finished protocol,
_ part of that ( the main body part ) can be isolated into a functioning variable , MyLengthyStreaming , and used in the typical LECMO (http://www.excelfox.com/forum/showthread.php/2240-VBA-referring-to-external-shared-Libraries-1)-Early-1-5)-Laterly-Early-and-2)-Late-Binding-Techniques) technology code lines of the form
CDO.Message.HTMLBody = MyLengthyStreaming
CDO.Message.Send
( In actual fact the entire Word.htm HTML string, TotalFile , could usually be used, but I do not do this as
_ TotalFile has a lot of unnecessary text, presumably needed for Word .htm file recognition
as well as
_ there are some subtle problems which need to be addresses with the string before it can be used with German Telekom, as it appears that a Bug means that the German Telekom does not quite recognise correctly that standard HTML coding ( gmail and AOL seem not to have this problem ) https://telekomhilft.telekom.de/t5/E-Mail-Center/Text-Formatieren-behalten-von-Word-wenn-Einfuegen-in-Telekom-E/m-p/3136416#M129791 )

What basically needs to be done is to modify the TotalFile at the main body part. This Part of the text is almost empty at this stage. That almost empty main body part is replaced by a made pretty HTML table
It is all done in a bit of a messy way, and it is easy to lose track of what is going on. Once again, the purpose of this code:
The code Sub MakeTagList(), primarily
_ makes a simple text file with the important details from a Daily Diet Protocol
_ makes a long string of HTML coding which if written to a text file, (but with the usually given .txt extension replaced with .htm ), is recognised by Microsoft Word and can opens it in a form which looks similar to a normal Word doc


_ makes a long string of HTML coding which if written to a text file, (but with the usually given .txt extension replaced with .htm ), is recognised by Microsoft Word and can opens it in a form which looks similar to a normal Word doc
In Rem 7 we basically embed a Table ( in HTML coding form ) by doing a simple Replace of the start part of the main body in the string from the Template .htm file which looks like this
<div class=WordSection1> ( You can see that yourself if you open up the .htm file using a simple text editor, and look towards the end MainWordSectionBody.JPG : https://imgur.com/HWjHTyz )
That existing HTML coding, <div class=WordSection1> , is Replaced by
<div class=WordSection1> & A made HTML table done in a Function
That Function is called using the arrNuts() thus:
ProTble(arrNuts())

Function ProTble()
By a bit of trial and error and learning some basic HTML coding I was able to write this function which based on the data given in arrNuts() gives a lot of HTML coding which a Browser ( or Word when it has it included in the long HTML string opened using a .htm extension file ) can understand and produce a table formatted as I want:

Rem 8
Back in the main code we now have our original full file text string of HTML coding, TotalFile , modified to include in it the pretty table
The string is printed out to a text file in the usually way but with the .htm extension instead of the usual .txt extension. This file is currently given the name
"DailyProtableFilled.htm"

Rem 8 Over write the last ( likely yesterdays ) filled file, with the modified template file which is mainly still that what Word recognises as we only modified a bit of the main text body
Dim HighwayToHelloPro As Long ' For rewrite of modified DailyProtable.htm as DailyProtable.htm2
Let HighwayToHelloPro = FreeFile(0)
Open ThisWorkbook.Path & "\" & "DailyProtableFilled.htm" For Output As #HighwayToHelloPro ' Will be made if not there, and overwritten as Output rahter than Append
Print #HighwayToHelloPro, TotalFile
Close #HighwayToHelloPro
Rem 9 get Word using Excel

Rem 9
The final part of the code, Sub MakeTagList() , which is initiated by the Button, MakeTagList , brings up the file, "DailyProtableFilled.htm" , temporarily in Microsoft Word.

_.___________

Required Files:
Daily Diet Protocol :
“ProAktuellex8600x2.xlsm” :
https://app.box.com/s/fpztob9pcp92fl6hh81zgpzumw9ntcp0 ( Current )
https://www.magentacloud.de/share/38m-zuc2y3#$/ ( April 2018 )

Main Makro File:
“NeuProAktuelleMakros.xlsm” :
https://app.box.com/s/e93u19xidygreeeenlxyupm750dxe33f ( Current )
https://www.magentacloud.de/share/38m-zuc2y3#$/ ( April 2018 )

Usually in practical use, the execution of the last coding would be followed by the sending of the EMail using the Send Pro Mail Button.








Ref:
http://www.eileenslounge.com/viewtopic.php?f=27&t=29556#p228710
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10528#post10528

DocAElstein
06-10-2018, 12:11 PM
Background testing work for this Thread:
http://www.excelfox.com/forum/showthread.php/2253-Automatic-sort-due-date-and-send-email
Also related to these Threads and Blogs

http://www.eileenslounge.com/viewtopic.php?f=27&t=29556#p228710
https://msdn.microsoft.com/en-us/library/ff519602(v=office.11).aspx#odc_office_UseExcelObje ctModeltoSendMailPart2_IntroductiontoSendingEMail
http://www.excelfox.com/forum/showthread.php/2146-%E0%A4%AC%E0%A5%8D%E0%A4%B2%E0%A5%89%E0%A4%97-%E0%A4%95%E0%A5%8B%E0%A4%B6%E0%A4%BF%E0%A4%B6-%E0%A4%95%E0%A4%B0-%E0%A4%B0%E0%A4%B9%E0%A4%BE-%E0%A4%B9%E0%A5%88-%D8%A8%D9%84%D8%A7%DA%AF%D8%B2-%DA%A9%DB%8C-%DA%A9*Trying-Blogs?p=10632#post10632
http://www.excelfox.com/forum/showthread.php/2233-Urgent-support-needed-Multiple-emails-multiple-Excel-workbooks-at-once#post10518


< HTML HTM > coding
At least until recently, the “language” most commonly used or seen in Internet and World wide web electronic communication is the “pointy bracket” type,” ( Hypertext Markup Language https://en.wikipedia.org/wiki/HTML https://www.youtube.com/watch?v=1gLhs5QycAE&list=PL1CD6F7E289625976 “ ) , which to a large part of most such coding consist of pairs of “start” and “stop” “tags” in a long string to tell something about what is within the tags, like, pseudo code example

<AText>This might be a final text you might “see” in something like an Internet Browser which can “read” HTML coding</AText><nextInstruction>………
or, for convenience this often is seen in a “.html” file, if viewed in the code form, like

<AText>
This might be a final text you might “see”…….
</AText>
<nextInstruction>………
( In a VBA code the last code string would be typically constructed something like this :

= “<AText>” & vbCrLf & “This might be a final text you might “ & “””” & “see” & “””” & ”…….” & vbCrLf & “</AText>” & “<nextInstruction> ….
Or this:
= “<AText>” & vbCrLf & “This might be a final text you might ““see””…….” & vbCrLf & “</AText>” & “<nextInstruction> ….…….. )

The extra carriage returns and / or Line feeds (vbCr , vbLf , vbCrLf ) , in the total string, as in the last code form would typically be ignored by any
Various software is available which can read that HTML coding. The most commonly known thereof being the internet browsers most commonly available, such as Internet Explorer from Microsoft, or Google Chrome from Google. Basically an Internet Browsers main function is to receive and read the HTML coding which is typically passed in Internet and World wide web electronic communication
So basically , if that HTML file is “fed” to something, such as an internet browser, then you, as final user/observer, would finally see something like this:

___This might be a final text you might “see” in something like an Internet Browser which can “read” HTML coding

Here an example of Internet browser, Google Chrome, used for receiving Emails , using the Email provider software of gmail and German Telekom
SeenIngmailOrGermanTelekom.JPG : https://imgur.com/Oz6z6tq
2068

Using this language you can make many other things “appear” in addition to simple text.

Currently I am interested in extending the “seen” message developed in posts around here, gmailInputRunOnThursday7thJune bw table.JPG : https://imgur.com/Dh38G4O , to include some colouring and possibly heading information

So I have this:
gmailInputRunOnThursday7thJune bw table.JPG : https://imgur.com/Dh38G4O
2066
But I want something more like this:

...... I wonder if we can include like the picture below.
2061…
2067
This is basically the Excel range format in the file from which the Information comes
Using Excel 2007 32 bit
Row\Col
A
B
C
D
E
F
G
H
I
J
K

1Equipment PM







2
Machine EQ.ID
Manufacture
Model
Description
Serial Number
Weekly
Date of Service
Weekly
Next Service
Monthly
Date of Service
Monthly
Next Service
Quarterly
Date of Service
Quarterly
Next Service


3







4
1JUKIGKG GLGL SCREEN PRINTERA123
06.04.2018
13.04.2018
15.03.2018
12.04.2018
N/A
N/A


18
137JukiK3Screen printerA137
03.06.2018
10.06.2018
N/A
N/A
N/A
N/A


19
141Heller1826 MK5Reflow OvenA138
N/A
N/A
13.05.2018
10.06.2018
N/A
N/A


20
142NISSANMCU-112A331.VForkliftA139
N/A
N/A
N/A
N/A
13.05.2018
10.06.2018


21
142NISSAN/yearly oil change and lubeMCU-112A331.VForkliftA140
N/A
N/A
N/A
N/A
N/A
N/A


22





28.01.1900
Worksheet: Equipment PM

_.___________________

HTML tolerates many mistakes + Microsoft files can be saved as .htm/html type
Here are a couple of interesting and relevant observations:
_(i) It would appear the HTML coding is quite tolerant of mistakes or having additional code lines, or Tag pairs that it does not recognise. Sometimes a large amount of coding will be accepted, and only a small part will be read and used successfully to give a “seen” output.
_(ii) Microsoft Word and Microsoft Excel Files can be saved as .htm extension instead of the more common extensions ( .xls , .doc , .xlsx etc…

Because of these two things, it is possible to save a File in such a way, and then use that as the HTML coding used in the Email sending codes which are being discussed here , ( https://tinyurl.com/y8gxucsl , https://tinyurl.com/yacekv4o , http://www.excelfox.com/forum/showthread.php/2253-Automatic-sort-due-date-and-send-email#post10670 , http://www.excelfox.com/forum/showthread.php/2233-Urgent-support-needed-Multiple-emails-multiple-Excel-workbooks-at-once#post10518 )

So, pseudo code part like this would be used



Dim strHTML As String: Let strHTML = The String of HTML coding obtained from a saved as .htm Word or Excel File
.htmlbody = strHTML


Such a technique is often done. Sometimes only a part of an Excel spreadsheet is wanted and this can also be saved in a .htm extension.
When using this technique, a lot of extra HTML coding is present which is not needed or recognised when used for the sent Email. As noted, this does not normally cause problems.
( often this technique goes by the name of Publishing or range publishing )
I personally prefer to examine the HTML coding and pick out only the information I need. This is the way I personally prefer to do it

In the next post I will look at this last way of doing things. I will use the example of the required ….. “….I wonder if we can include like the picture below ….”……
...... I wonder if we can include like the picture below.
2061…

DocAElstein
06-12-2018, 02:02 PM
Excel File (range) SaveAs .htm

As noted in the previous post, we can simply save an existing Microsoft Word or Excel file with the extension .htm
For a Word file there is not much more to it than that: the entire file is saved in a HTML code format, ( https://tinyurl.com/yash9gta
SaveAs Word.JPG Save As Word doc to htm.JPG https://imgur.com/h7XFAQX , https://imgur.com/vhRE9CC )

In this post , the case of an Excel file saved as .htm format is considered. In this case, if a range is selected before the SaveAs .htm, then at the Save action , an additional dialogue box comes up.
Consider us saving the header range:
Using Excel 2007 32 bit
Row\Col
A
B
C
D
E
F
G
H
I
J
K

2
Machine EQ.ID
Manufacture
Model
Description
Serial Number
Weekly
Date of Service
Weekly
Next Service
Monthly
Date of Service
Monthly
Next Service
Quarterly
Date of Service
Quarterly
Next Service
Worksheet: Equipment PM

SaveAs.jpg : https://imgur.com/ISfW7tH
SaveAshtm.jpg: https://imgur.com/muyoVqQ

After selecting .htm and Save for an Excel File, another Dialogue box pops up.
ExcelDialogueBoxRangeSelect htm.JPG : https://imgur.com/14iF2SM
At this point no file has been saved. One can see that one can choose to just save the selected Range, in this case, 'Equipment PM'!$A$2:$K$2

On attempting to save a second time, another Dialogue box pops up , which I don’t quite understand, _...
PublishExcelRange.JPG : https://imgur.com/6b5TV9j
_.. but on hitting Publish, the File appears to be saved:
SavedExcel htm.JPG : https://imgur.com/WapD7Sa
_.....

Examining saved htm file
A noted, such a file can be directly sent as the main body of an Email sent. This is commonly done.
I prefer not to do that.

My way of doing this is to examine the file and look for the relevant HTML coding which I need. In this case I need information about that spreadsheet range 'Equipment PM'!$A$2:$K$2

To simply examine the file, I open it with a simple text editor, ( and for convenience save it as such also )
RightClickOn htmFile OpenWithTextEditor.JPG : https://imgur.com/OpKEf8o
SaveAs txt File.JPG : https://imgur.com/ab1gXN8
Saved as Txt File.jpg. : https://imgur.com/ohhQ7td
Here is that File : “Equipment- Maint Records A2-K2 Header.txt” : https://app.box.com/s/uk3qnvuxizm10bvwoye1epg2zi1fs8qz

I am not an HTML expert, but with a bit of common sense , I start examining the code and looking for info relevant to an 11 cell row, A2-K2

This part looks promising:


<tr class=xl18712769 height=64 style='mso-height-source:userset;height:48.0pt'>
<td height=64 class=xl18312769 width=80 style='height:48.0pt;width:60pt'>Machine
EQ.ID</td>
<td class=xl18412769 width=207 style='width:155pt'>Manufacture</td>
<td class=xl18512769 width=113 style='border-left:none;width:85pt'>Model</td>
<td class=xl18612769 width=143 style='border-left:none;width:107pt'>Description</td>
<td class=xl18512769 width=158 style='width:119pt'>Serial Number</td>
<td class=xl19012769 width=115 style='border-left:none;width:86pt'>Weekly<br>
<span style='mso-spacerun:yes'> </span>Date of Service</td>
<td class=xl19012769 width=97 style='border-left:none;width:73pt'>Weekly<br>
<span style='mso-spacerun:yes'> </span>Next Service<span
style='mso-spacerun:yes'> </span></td>
<td class=xl19112769 width=154 style='border-left:none;width:116pt'>Monthly<br>
Date of Service</td>
<td class=xl19112769 width=154 style='border-left:none;width:116pt'>Monthly
<br>
Next<span style='mso-spacerun:yes'> </span>Service</td>
<td class=xl18812769 width=161 style='border-left:none;width:121pt'>Quarterly<br>
Date of Service</td>
<td class=xl19312769 width=161 style='width:121pt'>Quarterly <br>
Next Service</td>

Information that looks like it might be relevant is
_ The reference to widths
80
207
113
143
158
115
97
154
154
161
161
_ The reference to a “class”. If I look further in the code then I can glean some info about the background colour associated with those “classes” .
Class info in HTML text file.JPG : https://imgur.com/JmZdzmx
So this looks like the final 11 cell (column) information that could be relevant:
80
207 #D8D8D8
113
143 #D8D8D8
158
115 #92D050
97 #92D050
154 yellow
154 yellow
161 #D8D8D8
161 #D8D8D8


_._____________


Modifying code for Formatted header
Currently no header is included in the sent HTML string.
So it is convenient to construct a header manually as an addition to the start of the HTML string to be .Sended

This will be done in the next post

DocAElstein
06-13-2018, 02:31 PM
Simple HTML code string for a header table incl. background colour

We want a string to send as the .htmlbody in our code which will produce something of this form:


Machine EQ.ID
Manufacture
Model
Description
Serial Number
Weekly
Date of Service
Weekly
Next Service
Monthly
Date of Service
Monthly
Next Service
Quarterly
Date of Service
Quarterly
Next Service
Worksheet: Equipment PM
Lets say we put this in a sting variable, strHeader

The current String, held in variable strHTML already contains the data to be sent for that table, held in variable, ProTble.

Dim strHTML As String: Let strHTML = ProTble

So we simply can add our header then finally via
__Let strHTML = strHeader + ProTble

From the last post, we have the following information for column width and background color
80
207 #D8D8D8
113
143 #D8D8D8
158
115 #92D050
97 #92D050
154 yellow
154 yellow
161 #D8D8D8
161 #D8D8D8

Correspondingly from the Excel range we see the header text and so have
80 EQ.ID
207 #D8D8D8 Manufacture
113 Model
143 #D8D8D8 Description
158 Serial Number
115 #92D050 Weekly
97 #92D050 Weekly Nxt
154 yellow Monthly
154 yellow Monthly Nxt
161 #D8D8D8 Quarterly
161 #D8D8D8 Quarterly Nxt



Here is a basic HTML code string for the required table, ( The vbCrLf :are not needed and are ignored by any interpreting of the HTML string. We have them for convenience of viewing the code in an editor such as a simple Notepad text file. Also the _ _ _ are just for VBA code splitting of code lines, for convenience of viewing in VB Editors )


' Table start column info
Let strHeader = "<table width=1623>" & vbCrLf & _
"<col width=80>" & vbCrLf & _
"<col width=207>" & vbCrLf & _
"<col width=113>" & vbCrLf & _
"<col width=143>" & vbCrLf & _
"<col width=158>" & vbCrLf & _
"<col width=115>" & vbCrLf & _
"<col width=97>" & vbCrLf & _
"<col width=154>" & vbCrLf & _
"<col width=154>" & vbCrLf & _
"<col width=161>" & vbCrLf & _
"<col width=161>" & vbCrLf & vbCrLf
' single header row
Let strHeader = strHeader & _
"<tr height=17>" & vbCrLf & _
"<td> EQ.ID </td>" & vbCrLf & _
"<td style=""background:#D8D8D8""> Manufacture </td>" & vbCrLf & _
"<td> Model </td>" & vbCrLf & _
"<td style=""color:Black; background:#D8D8D8""> Description </td>" & vbCrLf & _
"<td> Serial Number </td>" & vbCrLf & _
"<td style=""background:#92D050""> Weekly </td>" & vbCrLf & _
"<td style=""background:#92D050""> Weekly Nxt </td>" & vbCrLf & _
"<td style=""background:yellow""> Monthly </td>" & vbCrLf & _
"<td style=""background:yellow""> Monthly Nxt </td>" & vbCrLf & _
"<td style=""background:#D8D8D8""> Quarterly </td>" & vbCrLf & _
"<td style=""background:#D8D8D8""> Quarterly Nxt </td>" & vbCrLf & _
"</tr>"


_.______

Results:
The initial results suggest that a bit of adjustments are necessary to get a convenient total width
InitialHeader gmail.JPG : https://imgur.com/D3xsfnu
InitialHeader t-online.JPG : https://imgur.com/QK68KcS


One possible simple way to do this adjustment is included in the final initial test code:

Rem 4.5) header row as HTML table
Dim strHeader As String, Adj As Double: Let Adj = 0.5
' 4.5a) Table start column info
Let strHeader = "<table width=" & 1623 * Adj & ">" & vbCrLf & _
"<col width=" & 80 * Adj & ">" & vbCrLf & _
"<col width=" & 207 * Adj & ">" & vbCrLf & _
"<col width=" & 113 * Adj & ">" & vbCrLf & _
"<col width=" & 143 * Adj & ">" & vbCrLf & _
"<col width=" & 158 * Adj & ">" & vbCrLf & _
"<col width=" & 115 * Adj & ">" & vbCrLf & _
"<col width=" & 97 * Adj & ">" & vbCrLf & _
"<col width=" & 154 * Adj & ">" & vbCrLf & _
"<col width=" & 154 * Adj & ">" & vbCrLf & _
"<col width=" & 161 * Adj & ">" & vbCrLf & _
"<col width=" & 161 * Adj & ">" & vbCrLf & vbCrLf
' 4.5b) Single header row
Let strHeader = strHeader & _
"<tr height=17>" & vbCrLf & _
"<td>EQ. ID</td>" & vbCrLf & _
"<td style=""background:#D8D8D8""> Manufacture </td>" & vbCrLf & _
"<td>Model</td>" & vbCrLf & _
"<td style=""color:Black;background:#D8D8D8"">Description</td>" & vbCrLf & _
"<td>Serial Number</td>" & vbCrLf & _
"<td style=""background:#92D050"">Weekly</td>" & vbCrLf & _
"<td style=""background:#92D050"">Weekly Next</td>" & vbCrLf & _
"<td style=""background:yellow"">Monthly</td>" & vbCrLf & _
"<td style=""background:yellow"">Monthly Next</td>" & vbCrLf & _
"<td style=""background:#D8D8D8"">Quarterly</td>" & vbCrLf & _
"<td style=""background:#D8D8D8"">Quarterly Next</td>" & vbCrLf & _
"</tr>"

The following results are then obtained
HalfWidthHeader t-online.JPG : https://imgur.com/Gup4W9t
HalfWidthHeader gmail.JPG : https://imgur.com/PpWtDKM

DocAElstein
06-13-2018, 04:46 PM
Simple HTML code string for a header table incl. background colour

We want a string to send as the .htmlbody in our code which will produce something of this form:


Machine EQ.ID
Manufacture
Model
Description
Serial Number
Weekly
Date of Service
Weekly
Next Service
Monthly
Date of Service
Monthly
Next Service
Quarterly
Date of Service
Quarterly
Next Service
Worksheet: Equipment PM
Lets say we put this in a sting variable, strHeader

The current String, held in variable strHTML already contains the data to be sent for that table, held in variable, ProTble.

Dim strHTML As String: Let strHTML = ProTble

So we simply can add our header then finally via
__Let strHTML = strHeader + ProTble

From the last post, we have the following information for column width and background color
80
207 #D8D8D8
113
143 #D8D8D8
158
115 #92D050
97 #92D050
154 yellow
154 yellow
161 #D8D8D8
161 #D8D8D8

Correspondingly from the Excel range we see the header text and so have
80 EQ.ID
207 #D8D8D8 Manufacture
113 Model
143 #D8D8D8 Description
158 Serial Number
115 #92D050 Weekly
97 #92D050 Weekly Nxt
154 yellow Monthly
154 yellow Monthly Nxt
161 #D8D8D8 Quarterly
161 #D8D8D8 Quarterly Nxt



Here is a basic HTML code string for the required table, ( The vbCrLf :are not needed and are ignored by any interpreting of the HTML string. We have them for convenience of viewing the code in an editor such as a simple Notepad text file. Also the _ _ _ are just for VBA code splitting of code lines, for convenience of viewing in VB Editors )


' Table start column info
Let strHeader = "<table width=1623>" & vbCrLf & _
"<col width=80>" & vbCrLf & _
"<col width=207>" & vbCrLf & _
"<col width=113>" & vbCrLf & _
"<col width=143>" & vbCrLf & _
"<col width=158>" & vbCrLf & _
"<col width=115>" & vbCrLf & _
"<col width=97>" & vbCrLf & _
"<col width=154>" & vbCrLf & _
"<col width=154>" & vbCrLf & _
"<col width=161>" & vbCrLf & _
"<col width=161>" & vbCrLf & vbCrLf
' single header row
Let strHeader = strHeader & _
"<tr height=17>" & vbCrLf & _
"<td> EQ.ID </td>" & vbCrLf & _
"<td style=""background:#D8D8D8""> Manufacture </td>" & vbCrLf & _
"<td> Model </td>" & vbCrLf & _
"<td style=""color:Black; background:#D8D8D8""> Description </td>" & vbCrLf & _
"<td> Serial Number </td>" & vbCrLf & _
"<td style=""background:#92D050""> Weekly </td>" & vbCrLf & _
"<td style=""background:#92D050""> Weekly Nxt </td>" & vbCrLf & _
"<td style=""background:yellow""> Monthly </td>" & vbCrLf & _
"<td style=""background:yellow""> Monthly Nxt </td>" & vbCrLf & _
"<td style=""background:#D8D8D8""> Quarterly </td>" & vbCrLf & _
"<td style=""background:#D8D8D8""> Quarterly Nxt </td>" & vbCrLf & _
"</tr>"


_.______

Results:
The initial results suggest that a bit of adjustments are necessary to get a convenient total width
InitialHeader gmail.JPG : https://imgur.com/D3xsfnu
InitialHeader t-online.JPG : https://imgur.com/QK68KcS


One possible simple way to do this adjustment is included in the final initial test code:

Rem 4.5) header row as HTML table
Dim strHeader As String, Adj As Double: Let Adj = 0.5
' 4.5a) Table start column info
Let strHeader = "<table width=" & 1623 * Adj & ">" & vbCrLf & _
"<col width=" & 80 * Adj & ">" & vbCrLf & _
"<col width=" & 207 * Adj & ">" & vbCrLf & _
"<col width=" & 113 * Adj & ">" & vbCrLf & _
"<col width=" & 143 * Adj & ">" & vbCrLf & _
"<col width=" & 158 * Adj & ">" & vbCrLf & _
"<col width=" & 115 * Adj & ">" & vbCrLf & _
"<col width=" & 97 * Adj & ">" & vbCrLf & _
"<col width=" & 154 * Adj & ">" & vbCrLf & _
"<col width=" & 154 * Adj & ">" & vbCrLf & _
"<col width=" & 161 * Adj & ">" & vbCrLf & _
"<col width=" & 161 * Adj & ">" & vbCrLf & vbCrLf
' 4.5b) Single header row
Let strHeader = strHeader & _
"<tr height=17>" & vbCrLf & _
"<td>EQ. ID</td>" & vbCrLf & _
"<td style=""background:#D8D8D8""> Manufacture </td>" & vbCrLf & _
"<td>Model</td>" & vbCrLf & _
"<td style=""color:Black;background:#D8D8D8"">Description</td>" & vbCrLf & _
"<td>Serial Number</td>" & vbCrLf & _
"<td style=""background:#92D050"">Weekly</td>" & vbCrLf & _
"<td style=""background:#92D050"">Weekly Next</td>" & vbCrLf & _
"<td style=""background:yellow"">Monthly</td>" & vbCrLf & _
"<td style=""background:yellow"">Monthly Next</td>" & vbCrLf & _
"<td style=""background:#D8D8D8"">Quarterly</td>" & vbCrLf & _
"<td style=""background:#D8D8D8"">Quarterly Next</td>" & vbCrLf & _
"</tr>"

The following results are then obtained
HalfWidthHeader t-online.JPG : https://imgur.com/Gup4W9t
HalfWidthHeader gmail.JPG : https://imgur.com/PpWtDKM

DocAElstein
11-09-2018, 12:24 PM
Test

[QUOTE=PG CodeRider]jdyjd[/Q
UOTE]


https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)
https://eileenslounge.com/viewtopic.php?p=318868#p318868 (https://eileenslounge.com/viewtopic.php?p=318868#p318868)
https://eileenslounge.com/viewtopic.php?p=318311#p318311 (https://eileenslounge.com/viewtopic.php?p=318311#p318311)
https://eileenslounge.com/viewtopic.php?p=318302#p318302 (https://eileenslounge.com/viewtopic.php?p=318302#p318302)
https://eileenslounge.com/viewtopic.php?p=317704#p317704 (https://eileenslounge.com/viewtopic.php?p=317704#p317704)
https://eileenslounge.com/viewtopic.php?p=317704#p317704 (https://eileenslounge.com/viewtopic.php?p=317704#p317704)
https://eileenslounge.com/viewtopic.php?p=317857#p317857 (https://eileenslounge.com/viewtopic.php?p=317857#p317857)
https://eileenslounge.com/viewtopic.php?p=317541#p317541 (https://eileenslounge.com/viewtopic.php?p=317541#p317541)
https://eileenslounge.com/viewtopic.php?p=317520#p317520 (https://eileenslounge.com/viewtopic.php?p=317520#p317520)
https://eileenslounge.com/viewtopic.php?p=317510#p317510 (https://eileenslounge.com/viewtopic.php?p=317510#p317510)
https://eileenslounge.com/viewtopic.php?p=317547#p317547 (https://eileenslounge.com/viewtopic.php?p=317547#p317547)
https://eileenslounge.com/viewtopic.php?p=317573#p317573 (https://eileenslounge.com/viewtopic.php?p=317573#p317573)
https://eileenslounge.com/viewtopic.php?p=317574#p317574 (https://eileenslounge.com/viewtopic.php?p=317574#p317574)
https://eileenslounge.com/viewtopic.php?p=317582#p317582 (https://eileenslounge.com/viewtopic.php?p=317582#p317582)
https://eileenslounge.com/viewtopic.php?p=317583#p317583 (https://eileenslounge.com/viewtopic.php?p=317583#p317583)
https://eileenslounge.com/viewtopic.php?p=317605#p317605 (https://eileenslounge.com/viewtopic.php?p=317605#p317605)
https://eileenslounge.com/viewtopic.php?p=316935#p316935 (https://eileenslounge.com/viewtopic.php?p=316935#p316935)
https://eileenslounge.com/viewtopic.php?p=317030#p317030 (https://eileenslounge.com/viewtopic.php?p=317030#p317030)
https://eileenslounge.com/viewtopic.php?p=317030#p317030 (https://eileenslounge.com/viewtopic.php?p=317030#p317030)
https://eileenslounge.com/viewtopic.php?p=317014#p317014 (https://eileenslounge.com/viewtopic.php?p=317014#p317014)
https://eileenslounge.com/viewtopic.php?p=316940#p316940 (https://eileenslounge.com/viewtopic.php?p=316940#p316940)
https://eileenslounge.com/viewtopic.php?p=316927#p316927 (https://eileenslounge.com/viewtopic.php?p=316927#p316927)
https://eileenslounge.com/viewtopic.php?p=316875#p316875 (https://eileenslounge.com/viewtopic.php?p=316875#p316875)
https://eileenslounge.com/viewtopic.php?p=316704#p316704 (https://eileenslounge.com/viewtopic.php?p=316704#p316704)
https://eileenslounge.com/viewtopic.php?p=316412#p316412 (https://eileenslounge.com/viewtopic.php?p=316412#p316412)
https://eileenslounge.com/viewtopic.php?p=316412#p316412 (https://eileenslounge.com/viewtopic.php?p=316412#p316412)
https://eileenslounge.com/viewtopic.php?p=316254#p316254 (https://eileenslounge.com/viewtopic.php?p=316254#p316254)
https://eileenslounge.com/viewtopic.php?p=316046#p316046 (https://eileenslounge.com/viewtopic.php?p=316046#p316046)
https://eileenslounge.com/viewtopic.php?p=317050&sid=d7e077e50e904a138c794e1f2115da95#p317050 (https://eileenslounge.com/viewtopic.php?p=317050&sid=d7e077e50e904a138c794e1f2115da95#p317050)
https://www.youtube.com/@alanelston2330 (https://www.youtube.com/@alanelston2330)
https://www.youtube.com/watch?v=yXaYszT11CA&lc=UgxEjo0Di9-9cnl8UnZ4AaABAg.9XYLEH1OwDIA35HNIei0z- (https://www.youtube.com/watch?v=yXaYszT11CA&lc=UgxEjo0Di9-9cnl8UnZ4AaABAg.9XYLEH1OwDIA35HNIei0z-)
https://eileenslounge.com/viewtopic.php?p=316154#p316154 (https://eileenslounge.com/viewtopic.php?p=316154#p316154)
https://www.youtube.com/watch?v=TW3l7PkSPD4&lc=UgwAL_Jrv7yg7WWC8x14AaABAg (https://www.youtube.com/watch?v=TW3l7PkSPD4&lc=UgwAL_Jrv7yg7WWC8x14AaABAg)
https://teylyn.com/2017/03/21/dollarsigns/#comment-191 (https://teylyn.com/2017/03/21/dollarsigns/#comment-191)
https://eileenslounge.com/viewtopic.php?p=317050#p317050 (https://eileenslounge.com/viewtopic.php?p=317050#p317050)
https://eileenslounge.com/viewtopic.php?f=27&t=40953&p=316854#p316854 (https://eileenslounge.com/viewtopic.php?f=27&t=40953&p=316854#p316854)
https://www.eileenslounge.com/viewtopic.php?v=27&t=40953&p=316875#p316875 (https://www.eileenslounge.com/viewtopic.php?v=27&t=40953&p=316875#p316875)
https://eileenslounge.com/viewtopic.php?p=316057#p316057 (https://eileenslounge.com/viewtopic.php?p=316057#p316057)
https://eileenslounge.com/viewtopic.php?p=315915#p315915 (https://eileenslounge.com/viewtopic.php?p=315915#p315915)
https://eileenslounge.com/viewtopic.php?p=316705#p316705 (https://eileenslounge.com/viewtopic.php?p=316705#p316705)
https://eileenslounge.com/viewtopic.php?p=316704#p316704 (https://eileenslounge.com/viewtopic.php?p=316704#p316704)
https://eileenslounge.com/viewtopic.php?p=176255#p176255 (https://eileenslounge.com/viewtopic.php?p=176255#p176255)
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

DocAElstein
11-09-2018, 12:42 PM
Copy of Reply to this:
https://www.thespreadsheetguru.com/blog/the-vba-guide-to-named-ranges#comment-4082118270


... to scope a workbook in a named range , best syntax is: ThisWorkbook.Names("YourName").RefersToRange.

Using ThisWorkbook.Range("YourName") will not work!
@ PG CodeRider. Hi!
_1) I’m not familiar with a syntax like ThisWorkbook.Names("YourName").RefersToRange.___ So I am not quite completely sure what you are saying. Can you clarify a bit please, thanks.
_2) & _3) :- These couple of points might be relevant somehow to the issue you are talking about

_Point 2).
This sort of thing, ThisWorkbook.Names("YourName").____ , I would expect would “do something sensible” as it will return a Name object. So then, to that Name object you could , for example , apply the Name property, and so , for example, rename the Named Range object. ( see '2(ii) in my demo code below).
In addition, it seems that the named Range object is one of those objects which if you “use” the object in a code part where a string is expected, rather than an object, then , instead of erroring with type mismatch as you might at first expect, a different phenomena occurs: In such a “usage” it actually “gives you” some string reference. In the case of a named Range, what it “gives you” appears to be the string reference of the range to which the Named Range refers, (see '2(iii)a) in my demo code below). You can use this strange phenomena then to actually change the referred to range , (see '2(iii)b) in my demo code below).
(This phenomena might be something to do with that the .Value property is usually the default property for an object)

_Point 3) I would not expect something like ThisWorkbook.Range("YourName") to ever “work” in most circumstances. The reason for this. I think, is simply that there is no Range property of a workbook.
As far as I know the main range “things” are the Worksheet range property and the Application Range “thing”. ( The latter is often called a property, but I sometimes think of it as a Method.. or “thing” )
In Rem _Point 3) of my demo code below I look at these ways of getting at a named range.
So, for example, something of this form ThisWorkbook.Application.Range(YourName").____ will usually “do something sensible”. For example, '3)(ii)b) and '3)(ii)c) in my demo code below is a version of what I call the “short hand way” of making a workbooks scope Named Range.
( I don’t think I can do anything similar to '2(iii)b) via the range things to actually change the referred to range , as I guess that might cause a chaos …. Maybe…. )
_.________________
If you want to try my demo routine below, Sub ObjRefValueWonkEtc() , make sure you also copy the other two routines, so three in total.

Alan



Sub ObjRefValueWonkEtc() ' https://www.thespreadsheetguru.com/blog/the-vba-guide-to-named-ranges#comment-4082118270
Rem 0) Clean the sheet of names
Call FukOffNames
Call getWbNames
Rem _Point 2) Name Object Names and Name string range references
'2(i) Add a Named range name object with workbook scope
ThisWorkbook.Names.Add Name:="YourFirstName", RefersTo:=ActiveSheet.Range("B1")
Call getWbNames
'2(ii) Use .Name property to change the name
Let ThisWorkbook.Names("YourFirstName").Name = "YourSecondName" ' Change name using name property of Name object
Call getWbNames
Dim objYourName As Object: Set objYourName = ThisWorkbook.Names("YourSecondName") ' use an object variable for the Name object
Call getWbNames
Let objYourName.Name = "YourThirdName" ' Change name using Name property of Name object again, ( using the object variable this time )
Call getWbNames
' Check info
'2(iii)a)
MsgBox prompt:="You last name for the cell B1 was """ & objYourName.Name & """" & vbCrLf & "and if you ""use"" that object where a string is expected like here in this MsgBox, then you get a reference looking like this: " & """" & objYourName & """"
'2(iii)b) use the string ""Value" property" to change the refered to range reference
Let objYourName.Value = "=" & ActiveSheet.Name & "!$B$2" ' give the typical full range reference for a cell
Call getWbNames
Dim strRef As String: Let strRef = objYourName ' this defaults probably to the next line
Let strRef = objYourName.Value
Rem _Point 3) Use range to access a Named Range
'3)(i) use Worksheets range property
Let ActiveSheet.Range(strRef).Value = "Allo4"
' Let Worksheets.Item(1).Range(strRef).Value = "Allo5" ' This will only work if the Named Range is in, that is to say, refers to, the first worksheet
' Let Worksheets.Item("NamedRanges").Range(strRef).Value = "Allo6" ' This will only work if the Named Range is in, that is to say, refers to, the worksheet with tab Name "NamedRanges"
'3)(ii)a) Use Application.Range "thing" to get at the named range
Let ThisWorkbook.Application.Range("YourThirdName").Value = "Allo1"
Let ThisWorkbook.Application.Range(strRef).Value = "Allo2"
Let strRef = Replace(strRef, "$B$2", "YourThirdName") ' replace the cell address with the name we last gave that cell
Let ThisWorkbook.Application.Range(strRef).Value = "Allo3"
Let Application.Range("=" & "'" & ThisWorkbook.Path & "\" & "[" & ThisWorkbook.Name & "]" & ActiveSheet.Name & "'" & "!" & "YourThirdName").Value = "Allo7" ' Just for fun to demo that Application.Range(" ") syntax will accept a full reference
'3)(ii)b) Give another names to an existing Named Range using "short hand way"
Let ThisWorkbook.Application.Range(strRef).Name = "YourforthName" ' Note this adds another name, it does not replace the existing one
Let ThisWorkbook.Application.Range(ActiveSheet.Name & "!" & "YourThirdName").Name = "YourfifthName" ' Note this adds another name, it does not replace the existing one
'3)(ii)c) Add a new named range using "short hand way"
Let ThisWorkbook.Worksheets.Item(2).Range("G4").Name = "WorkbookScopeNamedRangeInCellG4InSecondWorksheetOf ThisWorkbook"
Call getWbNames
Rem 4 Just for passing fun .. strange phenomena .. the next line won't work initially _....
Call FukOffNames: Call getWbNames
'4a) .. strange phenomena .. the next line won't work initially _....
'Let ThisWorkbook.Worksheets.Item(2).Range("G5").Name.Name = "WorkbookScopeNamedRangeInCellG5InSecondWorksheetOf ThisWorkbook"
' _.... But if I do this next line first, then it will work
Let ThisWorkbook.Worksheets.Item(2).Range("G5").Name = "WorkbookScopeNamedRangeInCellG5InSecondWorksheetOf ThisWorkbookName1"
Call getWbNames
Let ThisWorkbook.Worksheets.Item(2).Range("G5").Name.Name = "WorkbookScopeNamedRangeInCellG5InSecondWorksheetOf ThisWorkbookName2"
Call getWbNames
'4b) .. what is going on ... attempt to explain , ThisWorkbook.Worksheets.Item(2).Range("G5").Name = "WorkbookScopeNamedRangeInCellG5InSecondWorksheetOf ThisWorkbookName1" somehow made a named range object, and gave it the name "WorkbookScopeNamedRangeInCellG5InSecondWorksheetOf ThisWorkbookName1"
Dim objNameG5 As Name: Set objNameG5 = ThisWorkbook.Worksheets.Item(2).Range("G5").Name ' .. as I have a name object, then I can assign an object variable to it.
Call getWbNames
Let objNameG5.Name = "WorkbookScopeNamedRangeInCellG5InSecondWorksheetOf ThisWorkbookName3" ' this has now given a new name to the name Object, objNameG5
Call getWbNames
Let ThisWorkbook.Worksheets.Item(2).Range("G5").Name.Name = "WorkbookScopeNamedRangeInCellG5InSecondWorksheetOf ThisWorkbookName4" ' This does the same as objNameG5.Name = "WorkbookScopeNamedRangeInCellG5InSecondWorksheetOf ThisWorkbookName4"
Call getWbNames
End Sub





Sub getWbNames()
Dim Nme As Name, Cnt As Long
For Each Nme In ThisWorkbook.Names
Let Cnt = Cnt + 1
Dim strNames As String: Let strNames = strNames & Cnt & " "
If TypeOf Nme.Parent Is Worksheet Then ' Answer 2 - https://stackoverflow.com/questions/8656793/progammatically-determine-if-a-named-range-is-scoped-to-a-workbook
Let strNames = strNames & """" & Nme.Name & """ refers to the range ref """ & Nme & """ and and can be referenced only from worksheet with tab Name """ & Nme.Parent.Name & """ ( Worksheet Scope ). ( That worksheet is in the workbook """ & Nme.Parent.Parent.Name & """ )" & vbCrLf & vbCrLf
Else
Let strNames = strNames & """" & Nme.Name & """ refers to the range ref """ & Nme & """ and can be referenced from any sheet in the Workbook """ & Nme.Parent.Name & """ ( Workbook Scope )" & vbCrLf & vbCrLf
End If
Next Nme
If strNames = "" Then
MsgBox prompt:="I don't think you have any Names at the moment luvy"
Else
MsgBox prompt:=strNames, Title:="Spreadsheet Named range objects in " & ThisWorkbook.Name & " are:-"
End If
End Sub

Sub FukOffNames()
Dim Nme As Name
For Each Nme In ThisWorkbook.Names
Nme.Delete
Next Nme
End Sub


Edit: I added Rem 4 just to the post here at excelfox for fun as I have more space, and the code 'comments go to the right , so the code looks less cluttered
_.___________________
Edit 2 ...… a few hours later… after answering a few comments at the blog ( https://www.thespreadsheetguru.com/blog/the-vba-guide-to-named-ranges ) I understand now what you PG CodeRider means by “….to scope a workbook in a named range , best syntax is: ThisWorkbook.Names("YourName").RefersToRange….”
I see now that if I have an existing Named range with the name , "YourName" , then something like this will change the range it refers to
ThisWorkbook.Names("YourName").RefersToRange = "=Sheet1!$A$1"
So that answers my first question, 1)
_.________
Something like this will also work
Range("=Sheet1!$A$1").Name = "YourName"
The first time you use that, a Name object with the string name "YourName" is made if it does not already exist. ( It has workbooks scope and refers to the range $A$1 in Sheet1). Once it exists, then code lines like this will work to change the range it refers to, or its string Name

Application.Range("=Sheet1!$A$1").Name.RefersTo = "=Sheet1!$X$700"
Application.Range("YourName").Name.RefersTo = "=Sheet2!$A$100"
Application.Range("=Sheet2!$A$100").Name.RefersTo = "=Sheet3!$A$100"
Application.Range("YourName").Name.Name = "YourNewName"

I refer to a code line like Range("=Sheet1!$A$1").Name = "YourName" as a shorthand way to make a workbook scoped Named range. It is quite curious how/ why it works. I am not sure that I understand exactly how/ why it works. … Initially this, Range("=Sheet1!$A$1").Name , is returning a name object, not a name string. But a named range seems to be one of those objects which returns a reference string if you use the object variable in a place where a string is given or expected. Also I note that the default property of a lot of objects is .Value. I find that if I apply the .Value property to a Name object, then I get the same as if I apply the . RefersTo property. Somehow the result of all this is that a code line like Range("=Sheet1!$A$1").Name = "YourName" seems to make a named range object and give it the string name of "YourName”

DocAElstein
01-09-2019, 08:56 PM
Windows Update List.
This post is in support of this forum question answer:
http://www.eileenslounge.com/viewtopic.php?f=21&t=31572

A problem was encountered with a solutions previously used successfully on computers to produce a simple text file containing a list of all Windows updates. The solution was successful previously for computers with Operating systems Vista and Windows 7.
( http://www.excelfox.com/forum/showthread.php/2146-%E0%A4%AC%E0%A5%8D%E0%A4%B2%E0%A5%89%E0%A4%97-%E0%A4%95%E0%A5%8B%E0%A4%B6%E0%A4%BF%E0%A4%B6-%E0%A4%95%E0%A4%B0-%E0%A4%B0%E0%A4%B9%E0%A4%BE-%E0%A4%B9%E0%A5%88-%D8%A8%D9%84%D8%A7%DA%AF%D8%B2-%DA%A9%DB%8C-%DA%A9*Trying-Blogs?p=10582#post10582 )
The problem was that it appeared not to work for operating system XP.

The most important part of this solution that I present here is a free software, wul , from a person called Nir Sofer
https://www.nirsoft.net/utils/wul.html
http://launcher.nirsoft.net/downloads/index.html
In this Thread I may refer to this software, and/or results from it, as Wul , WinUpdatesList , WinUpdatesList software from NirSoft , or the wul stuff … etc.
This software from Nir Sofer does all the important stuff. My contribution is just to make it a bit more convenient to use specifically as I need , which is to allow me to compare the updates in different computers
The following posts walk through and explain the complete solution that I am using.

Download software and store in Folder
The software is downloaded to anywhere, and the entire contents of the Zip folder copied and pasted to a folder of choice, I use a Folder with the name Udates – The way this works for me is to simply select the entire Zip Folder contents, copy using Ctrl+c ( or by selecting the option from the selection given by clicking on the right mouse), and then in the clicking anywhere in the folder Updates and doing Ctrl+v , ( or selecting the insert or similar option from the selection given by clicking on the right mouse)
Copy Paste nirsoft wul.JPG : https://imgur.com/kuA67zm

Get HTML file WinUpdatesList __ HTML Report – All Items
Double click on wul.exe , and in the Window ( WinUpdatesList MYCOMPUTER ) , that should come up, select the icon to make a HTML copy.
HTML Report - All Items .JPG : https://imgur.com/OQRzvrZ
This will make a HTML file which is placed in the same folder as wul.exe. This HTML file can be read by some things to produce the output , which you may see automatically on a currently opened browser. This may depend on your own Browser and Browser settings. I use Google Chrome with standard settings, and I find that if my browser is opened when I select the icon to make a HTML copy, then in addition to the html file appearing in folder Updates, I also see a newly opened tab in my browser as shown in this screenshot below:
HTML report.JPG : https://imgur.com/DgbjPSg

What to do with that HTML file
My contribution is simply the manipulation of that HTML file.
I have a couple of possibilities. The simplest of which would be to just open that HTML file with a simple text editor, and re save that as a text, .txt , file. I could then use some VBA coding to take in that text along with some further VBA string manipulation code to get a Listing in some convenient form to read or further use, such in comparison with lists from different computers.

I have a possibility to do something slightly more advanced with HTML type things. This will allow me to then do the simplest thing mentioned above in a slightly more round about sort of a way, but also more usefully , I can do manipulation with the HTML string, taken as a pseudo “object” which allows me to do something equivalent to what would have been the string text manipulation, but I can do it in terms of using Properties and Methods of the “pseudo” object. ( As the concept of the object in VBA is itself somewhat imprecise, we can refer to a “pseudo” object and object as meaning the same for our purposes ).
I will describe briefly the adaptation of the Later that I will do, and give some reference to the ' code sections in the routine that I actually present ( http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10896#post10896
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10897#post10897
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10898#post10898 )

Rem 2 Building a “HTML object thingy” from the HTML file
This is generally seen done in the following way.
Objects from two different types/classes are used. ( Typically we talk about .. '2a XML requesting and '2b HTML Document object )
'2a Getting a long string of HTML coding
'2a usually uses something that has to do with HTML things and strings moving about. This is usually used for trying to get things around the internet, but as this HTML stuff is a sort of computer language used to make things on a screen in front of us that we can see in a meaningful form, then a HTML file can often be indistinguishable to some computer things from some large HTML string code floating around the Internet. That explains why we may see something in our internet browser if it is open, in addition to the window created specifically from the software wul. The browser will be basically reading meaningfully a form of the HTML file.
I am not sure if in this case that should happen, or it is an accident that the HTML file moving around our computer is “caught” by the browser as something that it might have considered to be coming from the internet. In any case , in '2a the xmlHTTP stuff object coming from a , MSXML2 , ( “Microsoft XML Passer” thing http://www.eileenslounge.com/viewtopic.php?f=30&t=31547#p244184 ) type/class library thing is the object used to get our HTML string. As far as I know that is a simple string of text. That will have mostly text characters including a lot of pointy brackets in it that we can see as well as things like Line feeds and carriage returns , so that it will be displayable if we open it in any typical text editor. There maybe other things in it which I am not aware of….. but if there are , I doubt there are many. So at the end of code section '2a we will have something that we could see in its raw form as the following. ( Something such as an Internet Browser, would recognise that as coding and produce the earlier screenshots ( HTML report.JPG : https://imgur.com/DgbjPSg )
Report as txt and HTML.JPG : https://imgur.com/mfsrXMN
Here are the files from that last screen shot . ( The .txt File is produced by saving that seen text file as report.txt instead of the seen report.html. ( If you down load those files and try to open them by simply double clicking on them, then there is a good chance that at least one of them might open somehow. It will depend a lot on what software you have and what settings you may have.)
report.html : : https://app.box.com/s/u3f885u8og1hfjed4npkgllyptyfc7dp
report.txt : https://app.box.com/s/u3f885u8og1hfjed4npkgllyptyfc7dp

'2b DOM stuff' Make OOP type model of HTML code, using Microsoft HTML Office Library
This basically takes in the string from '2a into an object of type/class with a name of htmlfile ( late Binding ) or HTMLDocument ( Early Binding )
At this stage we have an object made from the HTML coding stringto which we can apply various properties to manipulate indirectly the HTML coding string. In addition we have that simply string from '2a and could also do more direct manipulation of that.

So the next post will look at manipulation, primarily of the made OOP type model object, ( HTMLdoc ) , to give us a simple list of our updates.

DocAElstein
01-09-2019, 08:58 PM
Manipulation of string Directly and Indirectly
For now, I will mostly concentrate in this post on the indirect way of manipulation , that is to say through the use of the OOP type model object, ( HTMLdoc ). I will just briefly touch initially on looking at the simple string as a string of text..

Rem 3 Manipulation of string Directly and Indirectly
Rem 3a) Directly
I have not completed this section yet. I may come back to this later. The only thing I have done is to produce a simple text file from the HTML code string , PageSrc , which was obtained from '2a
Just for fun, if we compare the two text files, report.txt and the text file made in this section, strTextFile.txt then we see that they appear very similar.. in fact they appear to be the same, except that their size differs…. I will definitely come back to look at that later..…. ##
report_txt and strTextFile_txt .JPG : https://imgur.com/35eE19e
report_txt and strTextFile_txt .JPG : https://imgur.com/0MdFeUt

Rem 3b) (Rem 3b)(ii) ) Large Object from main made OOP type model object, ( HTMLdoc )
This is a small “ in between “ section , which I mainly do to keep in line with a typical way of doing coding of this type.
The OOP type model object, ( HTMLdoc ) is a large quite complicated object , which is probably difficult to relate to anything humanly perceivable. Generally we try to get at an “under object” either directly of through other objects. There probably are ways to get straight to a specific “thing” which we are after, but usually it is not done that way. If we always did that simple way, then it might put a lot of computer programmes out of work as the extra complication helps to give them something to do.
In this short code section we use the The .getElementsByTagName( ) method, which is a method available to our created HTMLdoc . This returns a collection of all elements in the document with the specified tag name, as a “NodeList” object. A NodeList object represents a collection of nodes. The nodes can be accessed by index numbers. The index starts at 0. The nodes can crudely be considered as simply points in our long string, and generally we talk in computing about nodes as the point in a string at a branch in a string type structure. The index number would usually represent nodes of the same level that also satisfy the condition in the ( )
This string structure can sometimes be seen in the way the indent is used in the HTML text files.
This is all somewhat academic to the fairly simple “html string file” that we are using, but in this way we are coming close to using the same coding as for getting information from the very large ( actually very long html string ) data strong that is used to show a typical internet site.
In our case the use .getElementsByTagName( ) has resulted in getting a collection object of just one item, ( which, incidentally , our HTMLdoc appears to have actually recognised as a table. Indeed, if we were using Early Binding, then we could of Dimed the object we use in the next section as a HTMLTable
oTable as HTMLTable.JPG : https://imgur.com/R309JjC
In a , ( possibly unnecessary round about sort of a way ) we finally have a “table object” , ( specifically a “html Dom object” HTMLTable ).
_.________________________________________________ ____

Rem 4 Manipulation of string Indirectly
We start here probably at the main point of the use of a OOP type model object, ( HTMLdoc ) in preference to a more straight forward way of string manipulation of either our report.txt or , strTextFile.txt file or PageSrc text String .
( Rem 4 would probably be better denoted by Rem 3b)(ii), but the use of Rem 4 is partly because it is a large section of a particular theme, that of the manipulation ( and partly just to keep in comparison with some other coding of this type that I have ) )

Code section '4b) Array generation from HTMLTable objects within “html Dom object”
This code section forms the main working to get a useable list of update data. It basically fills a data array using the “html Dom object” properties for the HTMLTable object which the last section has got us.
I will review how we got here and then go on to walk through this code section in more detail.
Review How did we get this far.
This review is specifically referring to the “HTML stuff and nonsense”…
We have originally been presented with a large string of text which looks like a lot of normal everyday text except that a lot of pointy brackets are included. This string text format characterises a typical “HTML” coding, which is one of the most common languages used for things moving around the internet. In the previous code sections we have used some tried and tested techniques, principally for using information from the internet, but which work equally well for our File containing that string of “pointy bracket text”. The result of using these techniques is that we have been able to supply a form of our original text , ( possibly in fact exactly the same, I am not sure yet ## ) , held in a simple String variable, PageSrc , into an object of a type/class going by the names of HTMLDocument for Early Binding and htmlfile for late binding. ( We use late binding , and note in parsing that we are dealing with a class that untypical works slightly differently in Early and Late binding : http://www.eileenslounge.com/viewtopic.php?f=30&t=31547#p244184 ) . This large main object is often named , htmlfile , HTMLdoc , html dom object , HTML document object … or similar
In our coding we use HTMLdoc for the variable for this main large object.
At the start of code section Rem 4 we have used a technique typically used to allow getting at “under objects “ from the main large “Dom” object. For our simple case we end up with an object known as a HTMLTable, which in simple terms could be thought of as an actual table full just as we want finally full with our update information.

The next detailed code description in the next post may appear more complicated than it is.
All we are doing is using the Properties of that table to build a simple array of our data. If you are familiar with a bit of VBA , then when dealing with “HTML Dom things” , a slight adjustment in your way of thinking can be helpful:
The properties that we use are approximately mainly to do with :

Rows : This can be considered as similar to rows type things in VBA and Excel generally.

Cells : In “HTML Dom things” generally and in “HTMLTable” things in particular, a regular row, column way of thinking as in a spreadsheet is not so common. It is more unusual to talk in terms of Cells. To a first approximation a Cell in a HTML Table and a spreadsheet could be considered similar. In general we do not talk in terms of column things.
What we can have, in addition to the entire cells for the table, is an additional Cells property for each row. So rather than getting at a Cell via a (r, c) type co ordinate system as in the case of a spreadsheet, we tend to do something different for a HTML table. For a MTHM Table we would tend to refer to a cell via something like pseudo
Table.Row(r).Cells(C)
So as comparison: In VBA coding generally we might see like this pseudo coding to loop through a range or a table
__For each row, r
____For each column, c
As comparison the equivalent pseudo coding when looking at HTML Table coding would be like:
__For each row, r
____For each row(r).cell(C)

Length : In HTML things, the word Length is often used where in other VBA things, the word Count might be used.


The next post will now look at a detailed walkthrough of code section 4b)

DocAElstein
01-09-2019, 08:58 PM
'4b)= =Building Array from HTML Table
There could be some erroneous / irrelevant 'comments in this particular coding as I am trying to keep iit comparable with some others that I have for web scrapping. So apologies for that. The walkthrough here should be specific for the issue at hand and approximately in line with the ' comments in the coding

I am doing a working example using my old Acer Aspire Lap top 4810TZG with Vista Operating System. If I use the WinUpdatesList software from NirSoft whilst my Google Chrome Browser is open then a new tab appears with a table in it. If I click on that, do a Ctrl+a , followed by a Ctrl+c, then click in the first cell of a spare Excel worksheet, and finally do a Ctrl+v , than I finally get a full worksheet looking something as shown here:
Worksheet report_html.JPG : https://imgur.com/FieBLkF
An example is in worksheet “report_html” in this file
“WMI Query.xlsm” : https://app.box.com/s/z15s0syizlct1nufhivl2yu4iupek8pi

In fact, that final table is more or less what I finally want. I forgot why I am trying to get that now in a complicated way, but never mind..
That table/range comes from the html coding string file , “report.html” . That html file is what my coding uses. So observation of that Excel worksheet table/range characteristics will be useful to have when developing and explaining the current code section, '4b) , under discussion. In particular it will be helpful to note the following characteristics of that excel worksheet table/range
_ It uses columns A-K. So we have 11 columns
_ In total there are 953 rows used.
_ For the actual data, rows 7 to 953 are used. So we have ( 953-7)+1 = 947 rows of data ( … that calculation comes from like say I have 10 rows of data from row 1 to row 10, then … (10-1)+1=10 )

Note: To get this routine to work, you will need to have 2 Files in the same ( any ) Folder …._
_... the file with the coding in it ,
as well as _..
_... the “report.html” file , within a folder “Updates”
ThisWorkbook Udates report_html.JPG : https://imgur.com/3udCqdW

The code line that requires this organisation of files is this:
_ Let strURL = ThisWorkbook.Path & "\Updates" & "report.html"
So if you have your coding and file organisation in some other way then you will need to adjust that code line appropriately : The full path and file name given in that line must be that of where the file "report.html" is

Remember:
To get that file, "report.html" , you need to run wul.exe and then select the HTML Report – All Items icon
HTML Report - All Items .JPG : https://imgur.com/OQRzvrZ
Re read again from here for more detail http://www.excelfox.com/forum/showthread.php/2146-%E0%A4%AC%E0%A5%8D%E0%A4%B2%E0%A5%89%E0%A4%97-%E0%A4%95%E0%A5%8B%E0%A4%B6%E0%A4%BF%E0%A4%B6-%E0%A4%95%E0%A4%B0-%E0%A4%B0%E0%A4%B9%E0%A4%BE-%E0%A4%B9%E0%A5%88-%D8%A8%D9%84%D8%A7%DA%AF%D8%B2-%DA%A9%DB%8C-%DA%A9*Trying-Blogs?p=10893#post10893

'4b)= =Building Array from HTML Table
'4b(i) returns us the table characteristics of
rowCnt = 948
colCt = 10428
colCnt = 11
For example, click in left margin to put stop on code, and run code, and hover over the variables with the mouse to see the contents of a variable:
rowCnt947.JPG : https://imgur.com/jEXoHrJ

'4b(ii) Looping through rows to build output array BASIC IDEA
At this point it might be worth a quick glance at a more simple code such as from Pike here : ( https://www.mrexcel.com/forum/excel-questions/367030-copy-table-website-into-excel-vba.html#post4026613 )

Set objTable = html.getElementsByTagName("table")
For lngTable = 0 To objTable.Length - 1
For lngRow = 0 To objTable(lngTable).Rows.Length – 1 ' For every row in a table .._
For lngCol = 0 To objTable(lngTable).Rows(lngRow).Cells.Length – 1 ' _.. Go along every cell in that row
ThisWorkbook.Sheets("Sheet2").Cells(ActRw + lngRow + 1, lngCol + 1) = objTable(lngTable).Rows(lngRow).Cells(lngCol).inne rText
Next lngCol
Next lngRow
ActRw = ActRw + objTable(lngTable).Rows.Length + 1
Next lngTable
End Sub
My coding in section '4b is in effect doing nothing more than that. I am basically looping through all HTML Cell s and preparing from that an output. The above code pastes out each HTML Cell content to a worksheet Cell as it goes along each cell in a row of the HTML table

My coding differs in that it first fills an array completely, which is the main purpose of '4b(ii)a - '4b(ii)b , and then finally does the pasting out in one go in '4b(ii)c.
My coding has additionally a more complicated way to get each array element which allows for the case , ( which we don’t actually have, but never mind ) of a html table within a html table, or similar , and additionally we can do some post processing for example selectively on each column. That can be useful for example to change frequently used long text to an abbreviation to make the final table more readable.

'4b(ii) Looping through rows to build output array. Walkthrough coding
__Rows are looped through, and at each row
____the cells in each row, which are effectively the columns in a classic sense, are looped through
All that is basically required at this point to fill our array , Data( , ) , would be a simple code line of like
_____ Data(r, C)= oTable.Rows(r).Cells(C).innerText
In such a code line, oTable.Rows(r).Cells(C) returns the ”HTML dom object model “ cell object, ( HTMLTableCell ) :
HTMLTableCell object.JPG : https://imgur.com/UT66C6D
In most simple coding the .innerText Property could be used to get the actual information that we want, for example in the first cell , we see “Name “ :
innerText.JPG : https://imgur.com/UT66C6D
( This would tend to suggest that the table we have found is , in fact the actual data, rather than the final output given by the WinUpdatesList software.
Name at top left of data.JPG : https://imgur.com/yU4jd7Z
The discrepancy in the total number of rows, I am not sure about at this stage )

Brief description of Sub GetElemsText
( I have this Sub GetElemsText from Leith Ross : https://www.mrexcel.com/forum/excel-questions/367030-copy-table-website-into-excel-vba-2.html#post4031122 )
You will see that I do not do the simple code line of
_____ Data(r, C)= oTable.Rows(r).Cells(C).innerText
The code line I do have , will in the vast majority of situations do exactly the same:
_____Call GetElemsText(oTable.Rows(r).Cells(C), Data(r, C))
The routine Sub GetElemsText is given the HTMLTableCell object coresponding to the r C values and from that puts the innerText for that cell in the array element Data(r, C)
It does it in a somewhat indirect way. Briefly in words: In the “html node tree structure” we have many nodes , and we can “go down” to the . ChildNodes(0) . ChildNodes(1) , ChildNodes(2) …. for as many as there are at the “next level down”. Even for the case of our simple cells we have two levels. The first does not refer to the level where the text is. The routine detects that and will keep “going down” until a node level corresponding to a text is found. This does not have much relevance for our situation, other than each Call of the routine results in it being done twice: the routine “Calls itself” which actually means that the routine pauses whilst a second copy of the routine is made. For our simple data example, the text is actually got on the second copy run of the routine. !!
This general process of the routine “calling itself” is the classic recursion process. This takes some careful and long explaining and is better demonstrated with a more complicated cell example using a reduced test data sample, see here for example: #####
Because of how this routine works, it does not actually get text from the run of the routine taking in the HTMLTableCell object, because the node associated with that is not a text. It is the “next node down” that is recognised as a text node !!
In addition, a further extra function of the routine is that when it does get at a text node, it first does an additional test to see if text was present as the current running copy of the routine. This would be the case of something like a paragraph: Since text will have been added before we finally come back up all the levels of the routine calling itself. The new text will then be concatenated with a "~" so that we could have the possibility to re split this text later. The second copy run of the routine at each Cell will take the same empty string with it which was supplied as the next array element to be filled in the previous ( fist copy) run of the routine

For the purposes of our requirement , the extra abilities of the routine should never be needed, but you never know… it does no harm to have it there , just in case….

_.___

'4b(ii)c Output from Array
I have left this section fairly simple for now as I may come back to it later, and adjust once I have used the routine a few times



_.________________________________________________ ________________________

Here is an initial File. I will likely customise it and the coding in it the next few days
WMI Query.xlsm : https://app.box.com/s/z15s0syizlct1nufhivl2yu4iupek8pi

Here again is the links to the initial coding:
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10896#post10896
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10897#post10897
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=10898#post10898

DocAElstein
02-25-2019, 01:46 AM
Positioning of procedure separation Line in the Visual Basic Development Environment

These are some notes based on a discussion here.. http://www.eileenslounge.com/viewtopic.php?f=30&t=31756
Lisa Green had noticed something strange in how VBA divides procedures.....

It appears that in VBA, that is to say in the Visual Basic Development Environment Window , ( that window seen by hitting Alt+F11 from a spreadsheet ) , the convention has been set to separate procedures by a line extending across the code pane Window.
We see these as appearing as a series of underscores, __________________ , extending across the Visual Basic Development Environment Window



End Sub ' The dividing line appears to us as a line of underscores ____




Usually, if we did write exactly this ' The dividing line appears to us as a line of underscores ____ ' , on that terminating line above , then we would not see those underscores, ____ , as they get hidden in the terminating line:
Hidden_____InDividingLine.JPG : https://imgur.com/7DyP9Om
21422176
The above screenshot shows the simplest case of routines with no "space" in between. In that simple case, the position of the dividing line is as expected in between the procedures. The situation is a bit more complicated if there is a separation in between procedures….

Effect of blank lines ( or 'commented lines ) In Between
Between procedures we may add blank lines or ' comment lines. If this is done, it appears that the convention has been set to place the line somewhere between the procedures in this blank/ 'comment range, and the lines above the line "belong" to the procedure above, that is to say the last or preeceding procedure, and the lines below the line "belong" to the procedure below, that is to say the next procedure, http://www.eileenslounge.com/viewtopic.php?f=30&t=31756#p245845

The documentation is not 100% clear on how the position of the dividing is determined , that is to say how the row on which it physically appears as a long series of underscores, __________________ is determined
There is no obvious logic to the way in which the dividing line can be positioned, that is to say , how to determine on which the dividing line appears as a long series of underscores, __________________

Some initial experiments suggest that is influenced by positioning of blank lines and any single underscores _

Line continuation / Break points : single underscores _
We note in passing , that single underscores are used in coding generally to allow us to divide a single line of code into several lines for ease of reading. For example:

' http://www.excelfox.com/forum/showthread.php/2293-Move-values-in-rows-at-the-end-of-the-preceding-row-*SOLVED*?p=10891#post10891
Sub LineContunuationUnderscores() ' https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/how-to-break-and-combine-statements-in-code
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row

' Without line breaks
Range("A1:A" & LastRow) = Evaluate(Replace(Replace("IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A#,"" "",""""),"","","""")),IF(LEFT(A1:A@,4)=""2018"",TRIM(A1:A@&"" ""&A2:A#),""""),IF(LEFT(A1:A@,4)=""2018"",A1:A@,""""))", "#", LastRow + 1), "@", LastRow))

' With Line breaks
LastRow = _
Cells(Rows.Count, "A").End(xlUp).Row
Range("A1:A" & LastRow) = Evaluate(Replace(Replace( _
"IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(" & _
"A2:A#,"" "",""""),"","","""")),IF(LEFT(A1:A@,4)" & _
"=""2018"",TRIM(A1:A@&"" ""&A2:A#),"""")," & _
"IF(LEFT(A1:A@,4)=""2018"",A1:A@,""""))", "#", _
LastRow + 1), "@", LastRow))
' This is _
acceptable in _
or out of a procedure
End Sub
' This is _
acceptable in _
or out of a procedure_________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ _________
Further, we note that the line continuation , sometimes called a line break, _ , also applies to comments whether in a procedure or between procedures:
' This is _
acceptable in _
or out of a procedure

_._________

Determining position of horizontal line dividing procedures when blank or comment lines are between procedures
Sir Narios .
The documentation is not 100% clear on how the position of the dividing is determined , that is to say how the row on which it physically appears as a long series of underscores, __________________ is determined
There is no obvious logic to the way in which the dividing line can be positioned, that is to say , how to determine on which the dividing line appears as a long series of underscores, __________________
Some initial experiments suggest that is influenced by positioning of blank lines and any single underscores _
There appear to be 3 scenarios to consider in order to place the line somewhere in between, ( 4 if you consider the simple case of all lines containing comments or all lines being blank )

Scenario 0
' _(0)
If all lines are blank, or all lines are full with comments ( which exclude line continuations )
No single underscores in any line
The break is immediately after the Last/ upper procedure. (This is the same as the case for no separation between routines )
Scenario 0 .JPG : https://imgur.com/pA4grFL
2143 2177

Sub Scenario_0()
' _(0)
End Sub_______________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ ______


Sub senario_0()
' _(0)
End Sub_______________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ ________________
'
'
'
Sub surnario_0()
' _(0)
End Sub_______________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ ________________________






Scenario 1
' _(i) 2141 SirNario_1.JPG . https://imgur.com/zmr2up2 2178
If no line continuations are present and there is a one or more blank lines, then the line before the first blank line down from the upper routine is taken as the break point.
No single underscores in any line

Sub Senario_1()
' _(i)
End Sub
'
'_________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ _________________________

Sub surnaria_1()
' _(i)
End Sub
'_________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ _____________________________

''

'
Sub Sirnario_1()
' _(i)
End Sub_______________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ __________


'
'
Sub snaria_1()
' _(i)
End Sub


Scenario 2
' _(ii) 2144 SirNario_2.JPG : https://imgur.com/D2LqloV 2179
If there are one or more line continuations present then the break point will be placed at the first blank line down after the last line after the line continuation … unless scenario (iii)

Sub Scnari_2()
' _(ii)
End Sub

''
'
' _

'_________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ _____________________________

'

Sub Sernario_2()
' _(ii)
End Sub
'
'
' _
'
'_________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ ____________________________

'
Sub Sirnarnio_2()
' _(ii)
End Sub

Scenario 3
' _ (iii) 2146 SirNario_3.JPG : https://imgur.com/ho56uBN 2180
There are no blank lines after the first line looking down after the last line continuation looking down, or after the first line looking down after the last line continuation looking down all lines contain comments . In this case, the break is at the line after the line on which the line continuation is on.


Sub scenario_3()
' _(iii)
End Sub
''
' _
__________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ ____________________________
'
'
Sub SirNario_3()
' _(iii)
End Sub

'
' _
'_________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ _____________________________
'
'
Sub snuaro_3()
' _(iii)
End Sub
'

'
' _
__________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ ____________________________





Sub SirNario_3()

End Sub
'
' _
'_________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ _____________________________



Sub SurNario_3()

End Sub


In the next post is some attempt at a worded explanation of the situation.

DocAElstein
02-25-2019, 01:56 AM
Following on from the last post ... and ......... some notes based on a discussion here.. http://www.eileenslounge.com/viewtopic.php?f=30&t=31756 .....Lisa Green had noticed something strange in how VBA divides procedures.... some "VB stangeness" .

_.............................



Worded conclusion
Attempting to put into words what is happening, or perhaps more of an attempt at words to fit the situation: ( Generally if I am referring to the sections between procedures, then this can also be taken as valid for the section between a last declaration at the top of a code module and the first procedure )
Scenario 0
The documentation tends to suggest that comments between procedures belong to the procedure below. This would suggest that the dividing line would be immediately below , for example , an End Sub. Indeed this situation is very typically seen. If all in between lines are comments then we see this. Given that the documentation states this, then it could be that something is in place to cause this positioning of the dividing line to behave in this way.
If not all lines are comments, then the situation might not particularly have been thought out and might have been left to chance
If all lines are blank then we see a similar situation: the dividing line would be immediately below , for example , an End Sub. This could be explained by no comments meaning the break point is simply left at immediately below , for example , an End Sub. There is no reason to think that the position as defined so far should be modified in this last situation
That all sound reasonable.

Now consider what might be a reasonable situation of wanting comments immediately below a routine and also wanting comments above a routine. This could be a reasonable requirement: Notes before or after things is a reasonable all day life situation to have.
Further reasonable assumption is that for neatness these 2 sets of comments would be separated for clarity by one or more blank lines. This leads on to
Scenario 1
If we have initially all comment lines, and then make one or more lines blank, then the dividing line “moves down” to the line before the first blank line. We could reasonably interpret this to .. the unbroken comments immediately below the last End as belonging to that last above routine, and a blank line signalising their end.

Option Explicit
'
'_________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ _____________________________
Empty Line
'
'
Sub SubAbove()

End Sub
' Comments under a sub
' last Comment under a sub_______________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ _______________________________
Empty Line
Empty Line
' First Comment above a Sub
' Comment above a Sub
Sub SubBelow()

End Sub( Above I am using Empty Line to signalise blank lines - In reality those lines are blank: Scenario1 Explanation.JPG : https://imgur.com/Jzd2nJZ 2181 )

Scenarios 2 an 3 general considerations ( Line breaks _ )
We are considering line breaks _ . More specifically in comment lines, ' ____
, since in between procedures or between a procedure
Most things in computing are in, reality, just long strings of characters. If you examine the string that you are able to obtain from the entire contents of a code module ( http://www.excelfox.com/forum/showthread.php/2302-quot-What%E2%80%99s-in-a-String-quot-VBA-break-down-Loop-through-character-contents-of-a-string?p=11016#post11016 ) then you find that
_ the long dividing lines across a module don’t seem to be within that string, and
_ the _ used as a line break appears as a normal character without any extra “hidden” characters other than the usually vbCr & vbLf associated with every line.
It is therefore a good assumption that some post processing is responsible for defining the behaviour of the underscore within comments in between procedures

Considering those two _ points above, I think we can further break an attempt to understand what is going on into one,
rather vague guess,
and a
further more reasonable set of explanations

Possibly there is some post processing in place which is designed to recognises a _ at the end of a module code line as linking a code line. Possibly its use in comments between procedures was not particularly considered. This could explain that a by product of this is that, which we observe, whereby a the dividing line never is placed above the line below a break point. In other words , you will never experience that in these two situations, _....


'
' _
'_________________________________________________ __________________________________________________ _________________________________
'

Sub Human()
' Poo
End Sub


' _
__________________________________________________ __________________________________________________ __________
'
'

_.. that the dividing line will be placed further up than I have indicated, ( There may be situations where they will be placed further down). An explanation of this could be that the post processing to determining the position of the dividing line may mistake that situation as a code line, and also therefore presume that it is an End type situation:


'
' _This_may_be_mistaken_as_a_code_line_with_a__
'___________break_line_in_it,_and_consequently_thi s_module_line_may_be_mistaken_as_an_End_procedure_ type_line_________________________________________ __________________________________
'

Sub Human()
' Poo
End Sub


' This_may_be_mistaken_as_a_code_line_with_a__
_________break_line_in_it,_and_consequently_this_m odule_line_may_be_mistaken_as_an_End_procedure_typ e line______________________________________________ ______________
'
'

If we assume that the above guess for the situation is correct, then scenario2 and scenario 3 , which are the scenarios when a _ is present between procedures, follow on directly from scenario0 and scenario1
If we assume that the first comment line looking up from a procedure with a trailing _ is as described above, considered as like a _pseudo End Sub__________

'
' _______
‘ _pseudo End Sub __________________________________________________ __________


It then follows,
Scenarion3 = Scenario0 and
Scenarion2 = Scenario1

Scenarion3 = Scenario0
All comment lines or all blank lines below the pseudo End

'
' _
_____pseudo End Sub_______________________________________________ __________________________________________________ ___
'
'
'
Sub Sconari3()

End Sub

'
' _
'_____pseudo End Sub_______________________________________________ __________________________________________________ ___________
'
'
'
Sub Scenari3()

End Sub

' _
'____pseudo End Sub_______________________________________________ ____________________________________


Sub Scenaro3()

End Sub

'
' _
______pseudo End Sub_______________________________________________ _________________________________________________


Sub Sceanrio3()

End Sub Scenarrio3.JPG : https://imgur.com/K8fSKrf : 2183
So we have the situation that comes close to the simple documentation inferred idea: Comments belong to the procedure below


Scenarion2 = Scenario1
( After the End ( real or pseudo ) not all lines are either all blank or all contain comments)
The first possibility to separate by a blank line is taken looking down from the End :

'
Option Explicit
'
' _
pseudo End of declaration section
'____Last comment in Declaration section __________________________________________________ __________________________________________________ __________

Sub Subsnario2()

End Sub
'
'
' Comments under a sub
' last Comment line _
_______under a sub______pseudo End Sub __________________________________________________ __________________________________________________ __________

' First Comment above a Sub
' Comment above a Sub
'

Sub Ssenario2()

End Sub

'
' _
_____pseudo End Sub __________________________________________________ __________________________________________________ __________


'
Sub Sconari2()

End Sub
'
' _
' pseudo End Sub
'
'_________________________________________________ __________________________________________________ ___________

Sub Scenari2()

End Sub

' _
'_____pseudo End Sub_______________________________________________ __________________________________________________ _____________

'
Sub Scenaro2()

End Sub

'
' _
______pseudo End Sub_______________________________________________ __________________________________________________ _____________


Sub Sceanrio2()

End Sub

Scnario 2 .JPG : https://imgur.com/WJF5JAb : 2184

_.________________________

The next post attempts the briefest summary possible:

DocAElstein
02-25-2019, 08:28 PM
Positioning of Border between routine sections in VBA. Summary

This is an attempt at a short summary, ( Edit: which failed, ….never mind :-) ).
For more details and justifications see the last two posts.
( https://tinyurl.com/yyw85dmg , https://tinyurl.com/yy9rwf85 )
Summary
In VBA, in a code module, coding sections, such as procedures and the initial Declaration section, may be directly following on, or may have sections in between which can be ' commented or blank lines , or combinations thereof.

For the case of coding sections directly following on from each other, the border , ( shown as a continuous light grey line across the code module ) , is in the obvious position

Option Explicit
Public LudwigII As Legend____________________________________________ __________________________________________________ _____________________________________
Sub Sub1()
‘ hkshh
End Sub_______________________________________________ __________________________________________________ __________________________________
Sub Sub2()
‘ asskasb
End Sub_______________________________________________ __________________________________________________ __________________________________
Function Funnky1()
‘ askjhsdh
End Function

For the case of separations of 1 or more lines in between the situation is less obvious.
The simple conclusion from the documentation is that the “comments above a routine belong to the routine below”
With a bit of imagination and lateral thinking, and working somewhat in reverse from knowing the answer, we can accept that, at least loosely.

The start point is to say that VBA somehow looks up from the top of a routine start code line, ( A routine start is a code line something of the form Sub MySub( ) or Function MyFunction( ) ) . In looking up, VBA does…..
_(i) attempt to find an “End” , after which a blank line is somewhere after ( looking back down ) .
_(ii) If it does not find one of those situations, then it stops looking at the “End”
This logic takes care of the simple situations of
_(i) all blanks in between
_(ii) all commented lines in between.

To deal with the mixed case of blank and commented lines we must consider carefully what an “End” is: The first two are obvious, the third is not.
In all cases they are not necessarily where the border line will be placed: remember the logic:
……….. VBA somehow looks up from the top of a routine and
_(i) attempts to find an “End” , after which a blank line is Present.
_(ii) If it does not find one then it stops looking at the “End”

What is an “End”
_a) an End ______ type code line: The last line of a routine which is coding: the terminating code instruction.
_b) The last declaration statement at the top of a module
_c) Whether by design or accident, VBA “sees” the next line down after a trailing _ as an “End” : Schematically like this:
'
' _ _
_______This line is seen as an “End” code line ( but may or may not contain the border Line____ )

'
'
( VBA will stop looking at the first “End” that it finds, even the situation _c) , so we only need concern pourselves with the fisrt trailing _ looking up from a procedure start code line

_._________________________________________


Here is just one, very limited, example, showing a slightly extended version of the first example above. This mainly shows the position of the "End"s
This example shows the effect of a trailing _ _
But there are other scenarios to consider with and without a _ which can lead to many different positioning of the border line, but which I think all can be explained through the logic discussed in this post. Note, for example, in all the examples below, the border is taken as the "End" line, but that does not need to be the case. It is in those examples below because either the next line is blank or there is no blank to be found.
The border line may be, but must not necessarily be, on an "End" line.

Option Explicit
Public LudwigII As Legend '__This is seen as a b) "End"__________________________________________________ __________________________________________________ ____________________
Sub Sub1()
' code
End Sub '____________________This is seen as a a) "End"__________________________________________________ __________________________________________________ _______
Sub Sub2()
' code
End Sub '_____________________This is seen as a a) "End"__________________________________________________ __________________________________________________ ______
Function Funnky1()
' code
End Function '_ _ _ _ _ _This would be seen as a a) "End", but isn't because VBA does not get this far – after looking back up from the procedure below, it mistakes the line after a _ as an “End”.

' Comments under a Sub
' last Comment line _
_______under a Sub________This is seen as a c) "End"__________________________________________________ __________________________________________________ ______

' First Comment above a Sub
' Comment above a Sub
'

Sub Ssenario2()
' code
End Sub

'








_.______________________________________________

Pseudo routine Logic
Finally a simple pseudo code of the logic. There are probably many different code logics which you could think up. Here is one.
In Words:
A prerequisite is to understand my suggested concept of a “End” line.
The routine starts at the signature or open line or routine Start Line…etc….for example, it starts at this sort of bit: Sub MySub()
It has a Main Outer Loop which goes up one row at a time, and it keeps Doing that until it finds an “End” line.
_________ If it finds an “End” then it goes back down line for line in an Inner Loop -- , looking for an blank line, and it keeps Doing that While it has not got back down to the original start point of the pseudo routine
_________________ If it is at a blank line at any time , in other words it found the fist blank line looking down, .. it jumps out that inner loop and Exit Sub after putting the thin grey border Line ___ in the previous line. So then it does not get further down in this case, and never reaches the original start point of the pseudo routine…. _
_.....The Inner Loop will not keep going down past the original start point …and if it gets that far then the grey border Line ___ is put in the “End” line. This last bit takes care of the cases of either no blank lines after the “End”, or no lines at all between code sections. If we arrive at this point the pseudo routine ends as we have done all that needs to be done.

Sub Start At_A_Procedure_Start_Line()
Do ‘ looking for a “End” line ‘ =========Main Outer Loop============================
Move up a row:- CurrentLine=CurrentLine-1
If now at End Sub, Or at End Function , Or at 1 row down from trailing _ Or at last module top Declare line then
Note this line as = “End” line
Do While not at Start of procedure ‘ Inner Loop back down to find blank line ----------
If current line is Blank then put light grey Border____in previous line : and Exit Sub‘ This will catch the next blank line as belonging to the procedure below ( also catches the case of all blank lines in between )
Move down a row ‘ I am moving down .. looking for a blank row
Loop ‘ -------------------------------‘ Inner Loop back down to find blank line -------
‘ At this point we got back as far down as the original start point without finding a blank line
Put light grey Border___in the “End” line and Exit Sub ‘ This will catch the situation of either no in between rows or all comments, because I get back to the start without finding any blank cells
Else
‘ We are still looking for a “End” line, which we do by moving up a row in the outer Loop
End If
Loop ‘ to keep trying to find a “End” line ======Main Outer Loop========================
DoneIt


_.__________________________


If you follow that above logic carefully then, as far as I can tell, it explains all the observed behaviour.
For detailed examples see the last two posts.
If you have an example and you are not clear about how your border has come about, then please post a reply here , so that I can take a look to
_ see if it fits my proposed logic
_ if it does fit the logic , then I will try to explain that in detail for you

Alan

DocAElstein
02-26-2019, 05:21 PM
Determining to which code section, comments outside procedures belong in VBA

This story is made up, just for fun. It assumes that the way the things discussed in the last three posts, happen was actually planned… (… it is probably anybodies guess if it was or wasn’t planned…. )

….VBA has an intelligent routine to determine to which code sections, the 'comments between code sections “belong”.…..

Dividing coding section in VBA : Dividing code sections in the VBIDE ( VB Editor )
At the top of a code module you can add things like declaration lines, global variable etc… -- things like

Option Explicit
' Any comment lines you want
Public myGlobalvariable As Long

That above can be considered as a coding section: it is a section of code.
The other types of coding sections are perhaps more obvious, thing like these two coding sections below

Sub mySub1()
Dim strStuff As String
_Let strStuff=”Hello”
_Call myFunctionToSaySomething(strStuff)
End Sub

Function myFunctionToSaySomething(ByVal Messige As String)
Msgbox(Prompt:=”Message was “ & Messige)
End Function


Those 3 sections can all be put in the same code module, ( The declaration section must be at the top ). There can be spaces in between the sections: Any amount of lines can be left in between. Those in between lines can be left blank or filled with
' comments
( Comments are usually ignored by any coding – you can put useful notes there, or write any profanities you choose, or URLs to porno sites etc… etc…. )

Border line______between code sections.
Excel adds automatically a thin grey line, across the code module window, to divide the code sections.
In the example above, if those coding sections were all in the same code module, then VBA adds two thin grey lines: One in between the two procedures and the other between the declaration section and the first procedure.
The VBA editor does not define an “in between” section. Instead, the lines in the space between is divided up between the code sections either side of the thin grey line. The convention is that the line in which the grey line appears to be in is the last line of the coding section above. To help remember this, you can imagine the border line to be made by typing a set of continuous underscores:
________–This line with the underscores in it, is the last line in the coding section above it. In fact if you typed this comment , ' ___ Some comments , as shown below, then you would not be able to see those green underscores as they get hidden in the grey border line which VBA adds to separate the code sections.

Option Explicit
Public LudwigII As Legend

Sub Sub1()
' code
End Sub ' ___ Some comments

Sub Sub2()
' code
End Sub

If you copied the above to an empty code module, then you would actually see, something approximately like this below
UnderscoresHiddenInLightGreyBorder.JPG : https://imgur.com/3kkjLW4

Option Explicit
Public LudwigII As Legend____________________________________________ _____________

Sub Sub1()
' code
End Sub '____Some comments __________________________________________________ _____

Sub Sub2()
' code
End Sub

( The underscores which you may have added, ___ , are there, - they are just “hidden behind” the grey border line )
Note: it is important in the above experiments to add some comments after a single underscore , or alternatively use more than one underscore. This is because a singly isolated trailing underscore , __ _
, can give interesting results, as we will discuss.

Intelligent routine to determine to which code sections, the 'comments between code sections “belong”.
Although the in between lines must belong to the upper or lower coding section, we can determine to a large extent to which. In other words, we can determine to a large extent where Excel places the long light grey border line_________
Excel uses an intelligent routine: Initially, as default, this is based on reasonable assumptions as to how you might typically lay out lines which you wanted to “belong” above or below. In addition an extra feature allows you to influence slightly, the final choice made by Excel.

Here is a summary of how the intelligent routine behaves:
How Excel determines where to put the____light grey border that divides coding sections in a code module

Situation 0a) All lines between used as comments.
Excel will assume you are not wanting to divide the comments up, as you have made no attempt to separate them. It will assume that it is more likely that these comments are intended to belong to the following code section. Correspondingly you will get this sort of behaviour in the lines in between:

End Sub_______________________________________________ ____________________
' Comment
' Comment
Sub Hello()

Situation 0b) All lines between are blank
Excel remains at the first default of Situation 0a)

End Sub_______________________________________________ _________________________


Sub Hello()

Situation 1a) Simple split of comments
You divide your comments by one or more consecutive empty lines, as you probably would for neatness if the lines above should belong to the coding section above, and the lines below to the next coding section. Excel positions the border appropriately

End Sub
' Comment for above
' Comment for above_____________________________________________ ___________________________

' Comment for below
' Comment for below
Sub Hello()


End Sub
' Comment for above
' Comment for above_____________________________________________ _______________________



' Comment for below
' Comment for below
Sub Hello()

Situation 1b) Simple split of comments , lower section has blank lines
After the initial blank separating line, or lines, any more below are left as blank lines

End Sub
' Comment for above
' Comment for above_____________________________________________ ________________________



' Comment for below

' Comment for below
Sub Hello()

Situation 2 Upper comments section has blank lines , lower section has blank lines
Situation 3 Upper comments section has blank lines , lower sections has all comment lines (no blanks), or lower section has all blank lines
Excel has a feature to allow us to do this. We have some flexibility in how to use it. It works as follows: Considering all the examples above, …. we note that Excel saw the …_
End Sub
_... as signalising the last code line of the coding section above.
The extra feature is that we can use either of these 2 possibilities within our in between section, the important part is an isolated trailing underscore _ _

' comment _
Empty line

' comment _
' comment

The effect of these is such that Excel will act in regard to the positioning of the__border line the same way as it would have, had it have seen the following in the second of those two line pairs above

' comment _
End Sub

' comment _
End Sub

The end result of this is that we can
_ have any combination of comment or blank lines above this point: Excel will no longer concern itself with those lines in terms of border position considerations: Those lines will always “belong” to the coding section above.
_ The lines below that effective End Sub will be subject to the same default rules already discussed. This allows us to make any combination of blank lines and comment lines below this point.

As far as I can tell, the only situation not possible to obtain would be to have more than one last empty lines belonging to the procedure above. All other situations should be possible. But I have not done lots of testing yet…

Here just a few final examples using the isolated trailing underscore _ _
In understanding how they come about you need to consider the furthest down isolated trailing underscore _ _
, as effectively making the line below it look like End Sub

End Sub
' Comment for above _

' Comment for above_____________________________________________ ___________________________________

' Comment for below

' Comment for below

Sub Hello()

End Sub
' Comment for above

' Comment for above _
__________________________________________________ _______________________________________

' Comment for below

' Comment for below

Sub Hello()

End Sub
' Comment for above

' Comment for above _
__________________________________________________ __________________________________________________
' Comment for below
' Comment for below
'
' Comment for below
'
Sub Hello()

End Sub
' Comment for above

' Comment for above _
__________________________________________________ _________________________________________________





Sub Hello()

Here below are those last 4 examples again, using the idea of the effective End Sub. If you then concentrate on the lines below this and consider them based on the original default rules, then the behaviour of the_______positioning is consistent with those default rules.

End Sub
' Comment for above _
End Sub
' Comment for above_____________________________________________ __________________________________

' Comment for below

' Comment for below

Sub Hello()

End Sub
' Comment for above

' Comment for above _
_End Sub_______________________________________________ ___________________________________________

' Comment for below

' Comment for below

Sub Hello()

End Sub
' Comment for above

' Comment for above _
_End Sub_______________________________________________ __________________________________________________ __
' Comment for below
' Comment for below
'
' Comment for below
'
Sub Hello()

End Sub
' Comment for above

' Comment for above _
_End Sub_______________________________________________ __________________________________________________ _





Sub Hello()



I won’t labour the point with more examples, but conclude with saying that you can use the extra feature, along with a knowledge of the default way that Excel behaves, to get the__border line at most positions, regardless of how you have your in between lines filled or not filled.







http://www.eileenslounge.com/viewtopic.php?f=30&t=31756&p=247408#p247408
http://www.excelfox.com/forum/showthread.php/2302-quot-What%E2%80%99s-in-a-String-quot-VBA-break-down-Loop-through-character-contents-of-a-string?p=11016&viewfull=1#post11016