Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2010, 10:40 AM
Silence Silence is offline Need help with macro Windows 7 Need help with macro Office 2007
Novice
Need help with macro
 
Join Date: May 2010
Posts: 1
Silence is on a distinguished road
Default Need help with macro

I need a macro that will replace the first word with the second one...



Example:

- John Johnson
- Patrick Something
- Annie Bunny

Convert to....

- Johnson John
- Something Patrick
- Bunny Annie

Can anyone help?

Thnx in advance...
Reply With Quote
  #2  
Old 06-17-2010, 02:58 PM
sixhobbits sixhobbits is offline Need help with macro Windows 7 Need help with macro Office 2007
Novice
 
Join Date: Aug 2009
Posts: 6
sixhobbits is on a distinguished road
Default

I'm sure there are more elegant ways, but the following seems to work if the names are all in a column i.e.

John Johnson
Patrick Something
Annie Bunny

Sub switchwords()
Dim ls As Integer
'change following number to number of names you want to change
ls = 1000
Selection.HomeKey unit:=wdStory
Do While ls > 0
Selection.MoveRight unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.EndKey unit:=wdLine
Selection.TypeText Text:=" "
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveDown unit:=wdLine, Count:=1
Selection.HomeKey unit:=wdLine
ls = ls - 1
Loop
End Sub

Just make sure to change the ls variable to be not much more than the number of names you have.

Consider using Excel for this - would be much easier.

HTH

SIxhbbits
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with macro Help with a macro Takket Word VBA 2 03-28-2014 04:58 PM
I need a macro, who can help me? Bahir Barak Word VBA 1 05-26-2010 12:24 AM
Macro help NEHicks503 Excel 0 04-16-2010 07:29 AM
Word macro weezypenguin Word 0 02-25-2010 01:25 PM
Need help with macro Macro Tutorials TAFE Word 4 11-04-2009 02:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:39 PM.


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