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




Reply With Quote
Bookmarks