Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2016, 04:41 PM
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

Ok getting a little clearer. Still bamboozled by the following



.Replacement.Text = "\3"
.Execute Replace:=wdReplaceAll

How does the replace work? what is \3 why does Greg use \2 and is this where the original tags are deleted?


.Text = "(\<" & arrTerms(i) & ")(\>)(*)\1/\2"

What is (*)\1/\2 doing it looks like jibberish?
Reply With Quote
  #2  
Old 03-30-2016, 05:12 PM
macropod's Avatar
macropod macropod 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 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by rpb925 View Post
.Replacement.Text = "\3"
.Execute Replace:=wdReplaceAll

How does the replace work? what is \3 why does Greg use \2 and is this where the original tags are deleted?
A wildcard Find can use brackets () to delineate certain segments of the expression for re-use. The Find expression:
.Text = "(\<" & arrTerms(i) & ")(\>)(*)\1/\2"
has 3 such delineated segments and it is the 3rd of these that gets re-used for the replacement. In Greg's code, there were just 2 such delineations and the 2nd gets reused.
Quote:
Originally Posted by rpb925 View Post
.Text = "(\<" & arrTerms(i) & ")(\>)(*)\1/\2"

What is (*)\1/\2 doing it looks like jibberish?
Not jibberish; just clever.

The:
(\<" & arrTerms(i) & ")(\>)
defines 2 segments of the Find expression for re-use: the string comprising the '<' and array entry for the 1st segment; and the '>' for the 2nd segment. A '\' is required before certain Find characters, including < and >.

The:
(*)
defines as a 3rd segment whatever follows the 2nd segment that precedes a repeat of the 1st segment, as indicated by the \1.

The:
\1/\2
says to repeat the 1st segment, insert the /, then repeat the 2nd segment.

FWIW:
.Text = "(\<" & arrTerms(i) & ")(\>)(*)\1/\2"
is the same as:
.Text = "\<" & arrTerms(i) & "\>(*)\<" & arrTerms(i) & "/\>"
for which the replacement would be \1.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-31-2016, 03:14 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

Far out it's like a puzzle. Thanks heaps for the break down. I feel like I'm getting close to getting a grasp on it but I still need to re-read the explanation another couple of times sleep on it and muck around with both your codes. This example just showed me how many ways there are to do the same thing, I hadn't realized. I thought it would be alot more constrained but it's more like pick your own adventure. Thanks for the help.
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 07:15 AM.


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