Re: Record Copy and Paste Macro, want to repeat throughout the document by JB
JB
Tue Apr 17 14:50:31 CDT 2007
On Apr 13, 1:57 pm, "Klaus Linke" <i...@fotosatz-kaufmann.de> wrote:
> > (((Before))))
>
> > dn: cn=user1,o=root
>
> > changetype:moddn
> > newrdn:
> > deletoldrdn:1
> > newsuperior: ou=NewOU,o=root
>
> > (((After)))
>
> > dn: cn=user1,o=root
>
> > changetype:moddn
> > newrdn:cn=user1
> > deletoldrdn:1
> > newsuperior: ou=NewOU,o=root
>
> Hi Jon,
>
> If I understand your sample, "cn=" always stays the same, in each record,
> but "user1" may vary ... right?
>
> First, we need to match "cn=user1" -- let's take the simplest wildcard
> expression:
> Find what: (cn=*)
>
> ... in brackets, so we can re-use it.
> Then, we need to match more text, up to "newrdn:":
> Find what: (cn=*),*newrdn:
>
> We want to leave evberything we matched, but insert "cn=user1" after that:
> Replace with: ^& \1
>
> That should work, if all the records look like the sample. But it's a pretty
> simple wildcard expression.
> You could make it much more complex, but safer, say so that it never spans
> more than one record, or observes other restrictions.
>
> Regards,
> Klaus
>
> "JB" <jon.jeffer...@gmail.com> schrieb im Newsbeitragnews:1176478977.008851.87800@e65g2000hsc.googlegroups.com...
>
> > On Apr 13, 10:02 am, "Klaus Linke" <i...@fotosatz-kaufmann.de> wrote:
> >> Hi Jon,
>
> >> Your macro doesn't work with the sample you posted (there's no
> >> "newrdn:"),
> >> so I'm not sure what it's supposed to do.
>
> >> So let me make a sample that works...:
>
> >> ((Before))
> >> ~~~~~~~~~~~~
> >> dn: cn=group,ou=org,o=root
> >> changetype:modify
> >> add:equivalentToMe
> >> equivalentToMe:cn=name,o=root
>
> >> replace:Member
> >> Member:
>
> >> ~~~~~~~~~~~~
>
> >> ((After))
> >> ~~~~~~~~~~~~
> >> dn: cn=group,ou=org,o=root
> >> changetype:modify
> >> add:equivalentToMe
> >> equivalentToMe:cn=name,o=root
>
> >> replace:Member
> >> Member: cn=group
>
> >> ~~~~~~~~~~~~
>
> >> You could do that with a wildcard replacement.
> >> In the "Find/Replace" dialog, check "Match wildcards".
>
> >> First, you'll have to figure out what you want to copy to the other
> >> location, and put it in braces:
> >> Find what: dn: (cn=[!,]@),
>
> >> The braces allow you to re-insert that expression later.
>
> >> Let's also match the following text, up to where we want to insert the
> >> group:
> >> dn:[!^13^11]@(cn=[!,]@),*Member:
>
> >> (Instead of both [!^13^11]@ and [!,]@ you could also use the * wildcard,
> >> but
> >> it's safter to restrict matches a bit)
>
> >> Now, we want to leave everything as it was, and insert a blank and the
> >> stuff
> >> from the second group:
> >> Replace with: ^& \1
>
> >> ^& inserts the whole stuff you matched, \1 puts in what you matched in
> >> your
> >> (first) braced expression.
>
> >> If that's not what you had in mind, exactly, maybe you can figure out how
> >> to
> >> adapt that wildcard replacement... or post back!
>
> >> Regards,
> >> Klaus
>
> >> >> Write a bit more about what you want the macro to do...
> >> >> You know you can copy stuff to the clipboard, and then replace some
> >> >> text
> >> >> with the (formatted) clipboard content, using ^c in "Edit > Replace >
> >> >> Replace with"?
> >> "JB" <jon.jeffer...@gmail.com> wrote:
> >> >> > I am new to writing macros in Word/VBA. I have recorded a macro
> >> >> > that
> >> >> > I need to repeat through the end of the document. All help is
> >> >> > appreciated.
>
> >> >> > Jon
>
> >> > Klaus,
>
> >> > Thank you for responding. OK, here is the macro I recorded. What I
> >> > need to do via a macro is copy, paste and repeat throughout the entire
> >> > document. The format of the document is:
>
> >> > dn: cn=group,ou=org,o=root
> >> > changetype:modify
> >> > add:equivalentToMe
> >> > equivalentToMe:cn=name,o=root
>
> >> > replace:Member
> >> > Member:
>
> >> > I need the macro to copy and paste the "cn=" portion from
> >> > "equivalentToMe:" to "Member:"
> >> > The following macro works but I need it to repeat through the entire
> >> > file, or if you have a better way of doing what I need, that would
> >> > help as well.
>
> >> > Selection.Find.ClearFormatting
> >> > With Selection.Find
> >> > .Text = "cn=""*"""
> >> > .Replacement.Text = "oldr"
> >> > .Forward = True
> >> > .Wrap = wdFindContinue
> >> > .Format = False
> >> > .MatchCase = False
> >> > .MatchWholeWord = False
> >> > .MatchAllWordForms = False
> >> > .MatchSoundsLike = False
> >> > .MatchWildcards = True
> >> > End With
> >> > Selection.Find.Execute
> >> > Selection.copy
> >> > Selection.EndKey Unit:=wdLine
> >> > Selection.Find.ClearFormatting
> >> > With Selection.Find
> >> > .Text = "newrdn:"
> >> > .Replacement.Text = "oldr"
> >> > .Forward = True
> >> > .Wrap = wdFindContinue
> >> > .Format = False
> >> > .MatchCase = False
> >> > .MatchWholeWord = False
> >> > .MatchWildcards = False
> >> > .MatchSoundsLike = False
> >> > .MatchAllWordForms = False
> >> > End With
> >> > Selection.Find.Execute
> >> > Selection.MoveRight Unit:=wdCharacter, Count:=1
> >> > Selection.PasteAndFormat (wdPasteDefault)
> >> > Repeat
> >> > End Sub
>
> >> > Thank You,
>
> >> > Jon
> > Klaus,
>
> > Sorry about the macro/example. But here is a more accurate example of
> > what the above script does:
>
> > (((Before))))
>
> > dn: cn=user1,o=root
>
> > changetype:moddn
> > newrdn:
> > deletoldrdn:1
> > newsuperior: ou=NewOU,o=root
>
> > (((After)))
>
> > dn: cn=user1,o=root
>
> > changetype:moddn
> > newrdn:cn=user1
> > deletoldrdn:1
> > newsuperior: ou=NewOU,o=root
>
> > What I would like to happen is actually repeat those steps throughout
> > the entire document because this (see above example) is just one entry
> > in the document. There are many many more throughout the document.
> > Now correct me if I misunderstand, but what you are telling to me to
> > do is place brackets here (cn=user1) and here: newrdn:( ). Then use
> > 'Find/Replace', checking 'Use Wildcards' put in Find what: (*) (*)
> > and in the Replace with: field type in (\2) (\1). Is this correct?
>
> > thank you again,
>
> > Jon
Klaus,
Thank you for your help and advice, I appreciate it!
sincerely,
Jon