Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 52

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

  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    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:
    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 = "gggg[d=fg]2[/d]45[/8]x[ddd[Cl=XYZ][/Cl]Any 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/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg
    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=Ugyb8nmKKoXvcdM58gV4AaABAg
    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=Ugxq4JHRza_zx3sz0fx4AaABAg
    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=UgyhQ73u0C3V4bEPhYB4AaABAg
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgzIElpI5OFExnUyrk14AaABAg.9fsvd9zwZii9gMUka-NbIZ
    https://www.youtube.com/watch?v=jdPeMPT98QU
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 09-22-2023 at 05:15 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  2. #12
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Recursion Function to remove BB Code code tags, described in last two posts


    Code:
    '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
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  3. #13
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10

    BB Code Generating and Removing. Preparing Forum Post in Word

    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 ) )_......

    [color=red]I want this to be red[/color]

    [CODE]This I want to come out in Code Tags[/CODE]


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




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


    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-rule...rum-rules.html
    Other languages: http://www.excelforum.com/forums-rules/

    Here some of the available BB Codes:
    http://services.runescape.com/m=foru...9,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[color=white]________[/color]Text[color=white]_______[/color]with[color=white]_______[/color]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:
    [code]My________Text_______with_______Spaces[/code]

    This will then come out thus:
    Code:
    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-...tra-space.html
    '_- https://www.mrexcel.com/forum/about-...ml#post4369692
    '_- https://www.mrexcel.com/forum/about-...-%60-o00o.html
    '_- *1 https://www.mrexcel.com/forum/about-...ml#post4466491
    '_- *1 http://www.excelfox.com/forum/showth...ments#post9696
    '_- http://www.excelfox.com/forum/showth...Formating-Test
    '_- *2 http://www.excelforum.com/developmen...ml#post4513357
    '_- *2 http://excelmatters.com/excel-forums/#comment-199348
    '_- https://www.mrexcel.com/forum/about-...ml#post4752733

    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  4. #14
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10

    BB Code Generating and Removing. Preparing Forum Post in Word.

    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/viewtop...=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
    [color=green]'comments[/color]
    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):

    Code:
    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/viewtop...=25188#p195293
    http://wordribbon.tips.net/T008058_A...rtcut_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-...ml#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
    18
    This is discussed in
    19
    detail from the start of this Thread: http://www.excelforum.com/developmen...ly-needed.html
    20
    and also in more Threads then I can remember !
    Worksheet: Tabelle3


    '_- Here just a few Posts
    http://www.excelfox.com/forum/showth...=9821#post9821
    http://www.excelfox.com/forum/showth...-BB-Code/page3
    http://www.excelforum.com/developmen...ml#post4513357
    http://www.excelforum.com/suggestion...ml#post4355361
    http://www.excelforum.com/the-water-...ml#post4355240
    http://www.excelforum.com/excel-prog...ml#post4399581
    http://www.excelforum.com/the-water-...ml#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 )
    Last edited by DocAElstein; 12-21-2017 at 03:45 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  5. #15
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10

    VBA Remove BB Code Code Tags in text. Long way around of doing it :)

    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/viewtop...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

    [TagWord=Some]Any text[/TagWord] or [B]Any text[/b]

    An arbitrary string is given initially in code section Rem 1)
    "gggg[d=fg]2[/d]45[/8]x[ddd[Cl=XYZ][/Cl][B]Any text[/b]"


    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[ddd[B]Any text[/b]
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  6. #16
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Code described and ExPlained in last post



    Code:
    Sub LongWayOfDoingIt()
    10   Rem 1) Test string
    20   Dim strBBCode As String '
    30    Let strBBCode = "gggg[d=fg]2[/d]45[/8]x[ddd[Cl=XYZ][/Cl]]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
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  7. #17
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10

    Wild Things. You make my heart sing. They make everything.....Groovy ........ :)

    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/viewtop...=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=H...s_-_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_..
    [color=Green]This is green[/color] 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 _..
    [color=Green]This is green[/color]
    _.. 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:
    Code:
    [ & ( 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_..
    Code:
    [ & ( 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.

    Code:
     [\[]    ([!\]=]@)    (*     \])    (*)    \[/    (\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 [color. What [!\]=]@ 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: [b]SomeBoldText[/b] , 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 & ]
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  8. #18
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10

    Simple code to use the Find and Replace discussed in the last Post

    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"



    Code:
    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:
    Code:
    '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
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  9. #19
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10

    Full Code "Belt and Braces” Word Find Replace & string manipulation

    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
    [CENTER][B]Issue Forum for Issues suggestions for improvement Forum for Issues obfuscation[/B][/CENTER]
    This is OK
    [B]Issue Forum for Issues suggestions for improvement Forum for Issues obfuscation[/B]


    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,
    _.____________-

    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.
    Code:
    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
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  10. #20
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10

    Code part 2 of 4 parts

    Code part 2 of 4 parts


    Code:
    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
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •