#1
|
|||
|
|||
Insertbefore an array? help :(
Skill level-n00b
hi, id like to insert a symbol (an orange triangle) before every instance of a large list of letter combinations (a b, a c, a d ... etc) here is my broken code *makes my ms word not respond thanks in advance for any advice.... Code:
Sub insertbefore() ' ' insertbefore Macro ' ' Dim range As range Dim i As Long Dim TargetList TargetList = Array("z" & ChrW(9700) & "s", "p" & ChrW(9700) & "p", "p" & ChrW(9700) & "ð", "p" & ChrW(643), "p" & ChrW(9700) & "t", "p" & ChrW(9700) & "s", "b" & ChrW(9700) & "b", "b" & ChrW(9700) & "m", "b" & ChrW(9700) & "t", "t" & ChrW(9700) & "t", "t" & ChrW(9700) & "ð", "t" & ChrW(9700) & "w", "t" & ChrW(9700) & "v", "t" & ChrW(9700) & "l", "t" & ChrW(9700) & "f", "t" & ChrW(9700) & "h", "t" & ChrW(9700) & "s", "t" & ChrW(9700) & "m", "t" & ChrW(9700) & "k" & _ "t" & ChrW(9700) & "j", "t" & ChrW(9700) & "f", "t" & ChrW(9700) & "g", "t" & ChrW(9700) & "p", "t" & ChrW(9700) & "d", "t" & ChrW(9700) & "b", "t" & ChrW(9700) & "r", "t" & ChrW(9700) & "n", "d" & ChrW(9700) & "d", "d" & ChrW(9700) & "ð", "d" & ChrW(9700) & "j", "d" & ChrW(9700) & "t", "d" & ChrW(9700) & "p", "d" & ChrW(9700) & "r", "d" & ChrW(9700) & "b", "d" & ChrW(9700) & "f", "d" & ChrW(9700) & "w", "d" & ChrW(9700) & "n" & _ "d" & ChrW(9700) & "m", "d" & ChrW(9700) & "l", "d" & ChrW(9700) & "g", "d" & ChrW(9700) & "s", "d" & ChrW(9700) & "z", "d ChrW(658)", "d" & ChrW(9700) & "k", "d" & ChrW(9700) & "h", "k" & ChrW(9700) & "k", "k" & ChrW(9700) & "r", "k" & ChrW(9700) & "t", "k" & ChrW(9700) & "w", "k" & ChrW(9700) & "p", "k" & ChrW(9700) & "m", "k" & ChrW(9700) & "d", "k" & ChrW(9700) & "ð", "k" & ChrW(9700) & "b", "k" & ChrW(9700) & "s" & _ "k" & ChrW(9700) & "h", "k" & ChrW(9700) & "f", "g" & ChrW(9700) & "g", "g" & ChrW(9700) & "b", "g" & ChrW(9700) & "s", "g" & ChrW(9700) & "n", "g" & ChrW(9700) & "m", "f" & ChrW(9700) & "f", "v" & ChrW(9700) & "v", ChrW(952) & " " & ChrW(952), ChrW(952) & " h", "ð" & ChrW(9700) & "ð", "ð" & ChrW(9700) & "h", "s" & ChrW(9700) & "s", "z" & ChrW(9700) & "z", "z" & ChrW(9700) & "ð", ChrW(643) & ChrW(9700) & ChrW(643) & _ ChrW(658) & ChrW(9700) & ChrW(658), "m" & ChrW(9700) & "m", "m" & ChrW(9700) & "p", "n" & ChrW(9700) & "n", ChrW(331) & ChrW(9700) & ChrW(331), "h" & ChrW(9700) & "h", "l" & ChrW(9700) & "l", "r" & ChrW(9700) & "r", "w" & ChrW(9700) & "w", "j" & ChrW(9700) & "j") ' put list of terms to find here For i = 0 To UBound(TargetList) Set range = ActiveDocument.range With range.find .Text = TargetList(i) .Format = True .MatchCase = True .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False Do While .Execute(Forward:=True) = True range.insertbefore ChrW(9660) .Size = 8 .Color = 49407 .Superscript = True .Subscript = False Loop End With Next End Sub Last edited by macropod; 08-13-2014 at 08:12 PM. Reason: Added code tags & formatting |
#2
|
||||
|
||||
You could use something along the lines of:
Code:
Sub InsertTriangleBefore() Dim RngDoc As Range, RngFnd As Range, i As Long, TargetList TargetList = Array( ... ) ' put list of terms to find here For i = 0 To UBound(TargetList) Set RngDoc = ActiveDocument.Range With RngDoc With .Find .Text = TargetList(i) .Format = True .MatchCase = True .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute End With Do While .Find.Found = True Set RngFnd = .Duplicate With RngFnd .Collapse wdCollapseStart .Text = ChrW(9660) With .Font .Size = 8 .Color = 49407 .Superscript = True .Subscript = False End With End With .Collapse wdCollapseEnd .Find.Execute Loop End With Next End Sub PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Wow, thank you Paul! works perfectly.
Is there a similar piece of code i can use for a new array, but to add a character boarder instead of highlight? If tried recording a macro but cant get it to work. Thanks again. |
#4
|
||||
|
||||
At whatever you regard as the appropriate location within the:
With RngFnd ... End With block, you can insert: .Borders.Enable = True
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Thanks, worked a charm!!
I have another question though.... Is there a way I can define all consonants, and vowels and then say。。。 If "vowel" & ChrW(9700) & "consonant" then .Borders.Enable = True ? Thanks again. |
#6
|
||||
|
||||
To box the whole 'word' containing the ChrW(9700), you could use:
Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "[aeiouy]" & ChrW(9700) & "[bcdfghjklmnpqrstvwxyz]*>" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found .Start = .Words.First.Start .Borders.Enable = True .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
amazing! but it boxes the whole of the second word, is there a way to just have it box the first letter?
Also, is there a way to add extra ’vowels’ to the list like eu, au, etc |
#8
|
||||
|
||||
You did say you wanted to do "vowel" & ChrW(9700) & "consonant", so of course the consonant gets boxed. I've also already told you how to limit the extent of the boxing.
You also didn't mention having multiple vowels. Now you say you want to have it "have it box the first letter". Which first letter? And what about when there are multiple vowels? Anything else you haven't mentioned?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
haha, im sorry (please forgive my noobity)
This is essentially what i want.... Code:
Sub Demo() ' ' demo Macro ' Application.ScreenUpdating = False With ActiveDocument.range With .find .ClearFormatting .Replacement.ClearFormatting .Text = "["i" & ChrW(720), ChrW(618), ChrW(650), u, e, i, ChrW(601), ChrW(601) & ChrW(720), ChrW(604) & ChrW(720), ChrW(596) & ChrW(720), ChrW(596), æ, ChrW(652), ChrW(593) & ChrW(720), ChrW(618) & ChrW(601), "e" & ChrW(618), ChrW(650) & "e", ChrW(596) & ChrW(618), ChrW(601) & ChrW(650), "o" & ChrW(650), "e" & ChrW(601), "a" & ChrW(618), "a" & ChrW(650)]" & ChrW(9700) & "[p, b, t, d, "t" & ChrW(643), "d" & ChrW(658), k, g, f, v, ChrW(952), ð, s, z, ChrW(643), ChrW(658), m, n, ChrW(331), h, l, r, w, j]*>" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .find.Found .Borders.Enable = True .Collapse wdCollapseEnd .find.Execute Loop End With Application.ScreenUpdating = True End Sub and, i do want "vowel" & ChrW(9700) & "consonant" boxed, but then the box continues to box off the rest of the word, it doesnt just stop at the consonant?! (sorry and thank you) Last edited by macropod; 08-15-2014 at 10:41 PM. Reason: Added code tags & formatting (again) |
#10
|
||||
|
||||
Did you read all of post #6? It contains instructions for how to limit the box to just the "vowel" & ChrW(9700) & "consonant".
To include one or more consecutive preceding vowels, simply change "[aeiouy]" to "[aeiouy]{1,}". If you want to be selective about which preceding vowel combinations it will accept, a different approach will been needed, but I'd need to know exactly which every one of those vowel combinations is - I don't propose to try to decipher them from the abysmal '.Text =' expression in your last post. In the meantime, you might try: Code:
.Text = "[aeiouyæ" & ChrW(593) & ChrW(596) & ChrW(601) & ChrW(604) & ChrW(618) & ChrW(650) & ChrW(652) & "]{1,}" _ & ChrW(9700) & _ "[!^32-^62\?\@aeiouyæ" & ChrW(593) & ChrW(596) & ChrW(601) & ChrW(604) & ChrW(618) & ChrW(650) & ChrW(652) & "]"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Hi, im sure im annoying you buy this point *soory. your last bit of code works great, but is there a way to swap around the but being connected? ie, have the words ending in consonants to connect to words begining with vowels (the opposite of whats happening now).
Also, could you explain to me how to add more to this code ("au", "ei", etc) i dont understand what the `!^32-^62\?\@` does thanks for your help Code: HTML Code:
.Text = "[wrtpdfghklvbnm" & ChrW(593) & ChrW(596) & ChrW(601) & ChrW(604) & ChrW(618) & ChrW(650) & ChrW(652) & "]" _ & ChrW(9700) & _ "[aeiouya" & ChrW(593) & ChrW(596) & ChrW(601) & ChrW(604) & ChrW(618) & ChrW(650) & ChrW(652) & "]" This is the code i have so far, all of the vowels and cons work, but none of the ChrW characters work. how can i get the characters to work, but also character combinations like ... letter "a" on its own and letter "a&ChrW(601)" together? Last edited by n00bie-n00b; 08-18-2014 at 11:48 PM. Reason: update |
#12
|
|||
|
|||
connecting combinations of letters? (smart people help needed)
Hi im trying to connect words ending in consonants to words beginning with vowels with a box, ie... bugger off
this is the code i have, works great for the consonants connecting to the vowels, but wont let me connect the special characters?!? any ideas? Also thanks for your help Code:
Sub newconnectttttt() ' ' newconnectttttt Macro ' ' demo Macro ' Application.ScreenUpdating = False With ActiveDocument.range With .find .ClearFormatting .Replacement.ClearFormatting .Text = "[wrtpdfghklvbnm" & ChrW(593) & ChrW(596) & ChrW(601) & ChrW(604) & ChrW(618) & ChrW(650) & ChrW(652) & "]" _ & ChrW(9700) & _ "[aeiouya" & ChrW(593) & ChrW(596) & ChrW(601) & ChrW(604) & ChrW(618) & ChrW(650) & ChrW(652) & "]" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .find.Found .Borders.Enable = True .Collapse wdCollapseEnd .find.Execute Loop End With Application.ScreenUpdating = True End Sub how can i get the characters to work, but also character combinations like ... letter word ending in consonant to connect to "a" on its own, but also consonant connect to letter "a & ChrW(601)" together? thanks guys Last edited by n00bie-n00b; 08-19-2014 at 12:09 AM. Reason: more descripton |
#13
|
||||
|
||||
Quote:
Code:
.Text = "[!^32-^62\?\@aeiouyæ" & ChrW(593) & ChrW(596) & ChrW(601) & ChrW(604) & ChrW(618) & ChrW(650) & ChrW(652) & "]" _ & ChrW(9700) & _ "[aeiouyæ" & ChrW(593) & ChrW(596) & ChrW(601) & ChrW(604) & ChrW(618) & ChrW(650) & ChrW(652) & "]{1,}" Quote:
Quote:
PS: Since your newest thread is really a continuation of the discussion already underway, I've merged the threads.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#14
|
|||
|
|||
ok thank you, *i did try switching it and it didnt work, i must have made a mistake* (but now works perfectly with the bit of code you gave me..... except 1 thing....
sometime for instance "dʒ" (as 1 letter) trying to connect to a vowel, only the "ʒ" connects?! so i wan to connect a few 'double' consonants "dʒ" and "tʃ" etc, but only those, not all consonants.? thankya! Last edited by n00bie-n00b; 08-19-2014 at 07:34 PM. |
#15
|
||||
|
||||
As I've already said a couple of times, if you want to match specific pairs (whether they be vowels or consonants), a different approach is required and I'd need to know what those pairs are. For the dʒ" and "tʃ", one would need to hold those strings in an array and do some array processing.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
complex, connected, insert, macro, n00b |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Adding information from a array into a table | jcorti | Word VBA | 4 | 01-10-2014 10:58 PM |
Convert String Array to Integer Array from a User Input? | tinfanide | Excel Programming | 4 | 12-26-2012 08:56 PM |
Complex array formula | andrei | Excel | 9 | 02-03-2012 03:40 AM |
How to capture start and ending Ref. Nos. in an array | KIM SOLIS | Excel | 5 | 09-07-2011 07:43 AM |
Look up an array based on user input | johnsmb | Excel | 2 | 01-07-2011 01:12 PM |