Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2016, 06:53 AM
rpb925 rpb925 is offline Calling Sub Routine for Formatting recently Created Word Document Windows 7 64bit Calling Sub Routine for Formatting recently Created Word Document Office 2010 64bit
Novice
Calling Sub Routine for Formatting recently Created Word Document
 
Join Date: Mar 2016
Location: Sydney
Posts: 17
rpb925 is on a distinguished road
Default

Thanks alot guys especially Greg. I got it working in the main script but still can't get it going in a module it doesn't
know what I'm refering to when I use wdDoc but it does in the main script so that'll do. If it ain't broke.....
This is what I ended up using anyway.
Code:
arrTerms = Split("(\<italics\>)(*)(\<italics/\>)|(\<bold\>)(*)(\<bold/\>)|(\<indent\>)(*)(\<indent/\>)", "|")
  For lngIndex = 0 To UBound(arrTerms)
    Set wdRng = wdDoc.Range
    With wdRng.Find
      .Text = arrTerms(lngIndex)
      .MatchWildcards = True
      Select Case lngIndex
        Case 0: .Replacement.Font.Italic = True
        Case 1: .Replacement.Font.Bold = True
        Case 2: .Replacement.ParagraphFormat.LeftIndent = 72
      End Select
      .Replacement.Text = "\2"
      .Execute Replace:=wdReplaceAll
   End With
  Next

This seems like super great code that I will use again but i can't really work out how it works could you please break it down for me. And say add another section that replaces <tab> with a vbtab. So I can compare and see how it works. Any explanations would be great. Below I have sort of explained how I see it. Actually probably
better stated how I don't see it.



Code:
Code:
'So the first line you are creating a list/matrix 
with a single row and defining it as arr terms. I don't really 
get what the Split and the l or all the brackets and asterisks 
and backslashes are doing though.
arrTerms = Split("(\<italics\>)(*)(\<italics/\>)|(\<bold\>)(*)(\<bold/\>)|(\<indent\>)(*)(\<indent/\>)", "|")
'Creating a loop which is based on variable IngIndex 
running through as many times as there are items in the list 
For lngIndex = 0 To UBound(arrTerms)
' Setting Range as whole document?  
Set wdRng = wdDoc.Range
    With wdRng.Find
'Find the term from the list for example <italics>and I start to very lost 
      .Text = arrTerms(lngIndex)
'I assume this means it has to be exact match
      .MatchWildcards = True
'Have no idea what is going on here cause I can't work out where 
you have actually selected the text between the two terms 
that is <italics> and <italics/>
      Select Case lngIndex
        Case 0: .Replacement.Font.Italic = True
        Case 1: .Replacement.Font.Bold = True
        Case 2: .Replacement.ParagraphFormat.LeftIndent = 72
      End Select
'I believe this line deletes all the arrterms in the document 
but have no idea how or why or what "\2" is
      .Replacement.Text = "\2"
      .Execute Replace:=wdReplaceAll
   End With
"Goes to next in list
  Next
Would be great to understand it so I can use it in other instances for example I think I will need it for <tab> at some stage. Once again thanks heaps for all the help my project is really coming along.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding tables to Created word document whilst other word document open Help rpb925 Word VBA 18 03-30-2016 04:45 PM
Calling Sub Routine for Formatting recently Created Word Document Uploading a previously created bibliography to be used in a new document JennJenn79 Word 1 07-16-2015 09:34 PM
Calling Sub Routine for Formatting recently Created Word Document was document created using 2010 or 2013 TDOG Word 1 10-12-2014 03:37 PM
Copy format created by a conditional formatting spk Excel 2 04-10-2013 04:41 AM
Word crashing on "sort" routine Kayale Word 0 04-12-2010 04:54 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft