Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2014, 07:56 PM
n00bie-n00b n00bie-n00b is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2007
Novice
Insertbefore an array? help :(
 
Join Date: Aug 2014
Posts: 17
n00bie-n00b is on a distinguished road
Lightbulb 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
Reply With Quote
  #2  
Old 08-13-2014, 08:37 PM
macropod's Avatar
macropod macropod is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,347
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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
I'd also suggest using rather more frequent line breaks in your array definition...

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
[MS MVP - Word]
Reply With Quote
  #3  
Old 08-13-2014, 09:52 PM
n00bie-n00b n00bie-n00b is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2007
Novice
Insertbefore an array? help :(
 
Join Date: Aug 2014
Posts: 17
n00bie-n00b is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 08-13-2014, 10:34 PM
macropod's Avatar
macropod macropod is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,347
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

At whatever you regard as the appropriate location within the:
With RngFnd
...
End With
block, you can insert:
.Borders.Enable = True
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 08-15-2014, 08:34 PM
n00bie-n00b n00bie-n00b is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2007
Novice
Insertbefore an array? help :(
 
Join Date: Aug 2014
Posts: 17
n00bie-n00b is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 08-15-2014, 09:11 PM
macropod's Avatar
macropod macropod is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,347
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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
To box just the "vowel" & ChrW(9700) & "consonant", you could use the above without the '*>' and '.Start = .Words.First.Start'.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #7  
Old 08-15-2014, 09:46 PM
n00bie-n00b n00bie-n00b is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2007
Novice
Insertbefore an array? help :(
 
Join Date: Aug 2014
Posts: 17
n00bie-n00b is on a distinguished road
Default

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
Reply With Quote
  #8  
Old 08-15-2014, 10:14 PM
macropod's Avatar
macropod macropod is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,347
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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
[MS MVP - Word]
Reply With Quote
  #9  
Old 08-15-2014, 10:26 PM
n00bie-n00b n00bie-n00b is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2007
Novice
Insertbefore an array? help :(
 
Join Date: Aug 2014
Posts: 17
n00bie-n00b is on a distinguished road
Default

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
*but it doesnt work

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)
Reply With Quote
  #10  
Old 08-15-2014, 10:39 PM
macropod's Avatar
macropod macropod is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,347
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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) & "]"
Finally, as already requested in post #2, please use the code tags when posting code.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #11  
Old 08-18-2014, 11:18 PM
n00bie-n00b n00bie-n00b is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2007
Novice
Insertbefore an array? help :(
 
Join Date: Aug 2014
Posts: 17
n00bie-n00b is on a distinguished road
Default

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
Reply With Quote
  #12  
Old 08-18-2014, 11:56 PM
n00bie-n00b n00bie-n00b is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2007
Novice
Insertbefore an array? help :(
 
Join Date: Aug 2014
Posts: 17
n00bie-n00b is on a distinguished road
Default 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
(There is a symbol (ChrW(9700)) instead of a space if your wondering)
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
Reply With Quote
  #13  
Old 08-19-2014, 12:52 AM
macropod's Avatar
macropod macropod is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,347
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Quote:
Originally Posted by n00bie-n00b View Post
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).
Well, you could swap the terms around...
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:
Also, could you explain to me how to add more to this code ("au", "ei", etc)
As I said in my previous post, to explicitly work with specified vowel pairs only, a different approach would be required. At present, the code works with any vowel sequences of any length, but can quite easily be limited to, say, no more than two vowels by nothing more complicated than changing {1,} to {1,2}.
Quote:
i dont understand what the `!^32-^62\?\@` does
That is a wildcard expression telling the Find process to not make matches with characters anywhere in the ASCII 32 to 62 range, or with ? or @ characters.

PS: Since your newest thread is really a continuation of the discussion already underway, I've merged the threads.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #14  
Old 08-19-2014, 06:32 PM
n00bie-n00b n00bie-n00b is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2007
Novice
Insertbefore an array? help :(
 
Join Date: Aug 2014
Posts: 17
n00bie-n00b is on a distinguished road
Default

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.
Reply With Quote
  #15  
Old 08-19-2014, 09:11 PM
macropod's Avatar
macropod macropod is offline Insertbefore an array? help :( Windows 7 32bit Insertbefore an array? help :( Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,347
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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
[MS MVP - Word]
Reply With Quote
Reply

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
Insertbefore an array? help :( Convert String Array to Integer Array from a User Input? tinfanide Excel Programming 4 12-26-2012 08:56 PM
Insertbefore an array? help :( 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

Other Forums: Access Forums - Senior Forums

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


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