Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-27-2015, 10:52 AM
Mark Calamus Mark Calamus is offline Problems with Macros in MSW2010 vs 2003 Windows XP Problems with Macros in MSW2010 vs 2003 Office 2010 32bit
Novice
Problems with Macros in MSW2010 vs 2003
 
Join Date: Aug 2015
Posts: 2
Mark Calamus is on a distinguished road
Unhappy Problems with Macros in MSW2010 vs 2003


Hi I am having difficulty recording a new macro to do the same task as I did happily in MSW2003. I do a lot of formatting of text and used a number of macros to achieve common tasks. I upgraded (finally!) to MSO2010 but lost all my macros and when recording new ones they simply don't do the actions I recorded.

For example one macro I use a lot is to search for a name, say John Smith, select and cut that name, move it up a couple of lines and paste it next to his picture, move down and select the next line (a date & time) and then do the same to that as to the name thus making one line of pic, name, date. Then to move down again and select that line to the end and change the colour of the text and make it italic.

I have a bunch of peoples data that I reformat in this way and it was very easy to do so under MSW2003. Record the actions, associate it with a button and save it (into Normal.dot) and off I go.

Under MSO2010 the macro doesn't seem to use the search function properly and randomly deletes and changes incorrect parts removing pictures and characters. Most annoying! I have tried it a dozen times and it hasn't functioned correctly once! I'm thinking it might be the search part that is the problem but I cannot figure out how to do a basic field search on MSW2010. Under MSW2003 I just used CTRL-F and searched for the next instance of John Smith. Under MSW2010 it tries to be very clever and give me lots of choices I just don't want!


Apologies for the length of this question - I am trying to give as much detail as possible.

Thanks in advance
Mark
Reply With Quote
  #2  
Old 08-27-2015, 01:30 PM
Charles Kenyon Charles Kenyon is offline Problems with Macros in MSW2010 vs 2003 Windows 8 Problems with Macros in MSW2010 vs 2003 Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,155
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

The find and replace function was modified a bit in Word 2010. Most macros will work fine and I have an extensive find and replace macro written for Word 2003 that works fine in Word 2013.

Are these macros that you recorded in Word 2010?

Not all actions are picked up by the macro recorder.
Reply With Quote
  #3  
Old 08-28-2015, 12:26 AM
gmayor's Avatar
gmayor gmayor is offline Problems with Macros in MSW2010 vs 2003 Windows 7 64bit Problems with Macros in MSW2010 vs 2003 Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you still have a copy of your old normal.dot file (Upgrading Word should not have deleted it) then you can import the macros from that template using the Organizer (ALT+F8 > Organizer). Whether they will work as before is another issue, but you can then test them.

There were big changes to the way graphics are used in 2010 vis-a-vis 2003 and that is equally likely to be the issue here. If you post a sample document we would be better placed to suggest code to handle it.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #4  
Old 09-03-2015, 11:36 AM
Mark Calamus Mark Calamus is offline Problems with Macros in MSW2010 vs 2003 Windows XP Problems with Macros in MSW2010 vs 2003 Office 2010 32bit
Novice
Problems with Macros in MSW2010 vs 2003
 
Join Date: Aug 2015
Posts: 2
Mark Calamus is on a distinguished road
Default

Thanks for your replies.


I am very interested in any solution though I would much prefer to understand why it is different to write a macro in MSW2010 than MSW2003. Can you explain how I might achieve the result using Find/Replace?


I rolled back to MSW2003 and the old macros all work fine as do new ones I created. I haven't tried to import the old macros into MSW2010 yet but fail to see why I can write them so easily in MSW2003 but the same instructions written to create a macro doesn't do what I typed in the record mode in MSW2010.


I have copied one macro from the 2003 template to show how basic the code is:


Sub Beige_M()
'
' Beige_M Macro
' Macro recorded 14/04/2015 by Mark Calamus
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Mark Calamus "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=vbTab
Selection.PasteAndFormat (wdPasteDefault)
Selection.TypeBackspace
Selection.TypeText Text:=vbTab
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Italic = wdToggle
Selection.Font.Color = wdColorDarkYellow
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1
End Sub

As I wrote previously All I want to do is cut-n-paste a name and then a time to the lines above, then format the text written below. It seems very simple and I can and have re-written the codes with small changes in MSW2003 and they work pretty much how I want.


To reiterate I think it is the 'find' (CTRL-F) part that is the problem.
Any further help would be appreciated - I really want to upgrade to MSW2010!


Cheers
Mark Calamus
Reply With Quote
  #5  
Old 09-03-2015, 07:44 PM
Guessed's Avatar
Guessed Guessed is offline Problems with Macros in MSW2010 vs 2003 Windows 7 32bit Problems with Macros in MSW2010 vs 2003 Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,991
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Writing VBA code is no different between those versions of Word. I can't see anything in your provided code that would act differently on versions of Word from 2003 to 2013. However, you could certainly improve the code to make it much clearer what is going on.

I suspect the problem you are seeing is because you are running the find and not actually testing to see whether it found anything (and moved the selection as a result) before doing the second part of the macro. Then the subsequent code would give wildly different results depending on the content above the found text (eg moving by two lines is different to moving by two paragraphs). If you test the macro on different files you will get different results but the version of Word appears irrelevant to your issue.

Perhaps you should explain what you want the macro to do so we can provide handwritten code that is a lot more error tolerant than what you recorded. You say you want to add the time but your code doesn't do that.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with Macros in MSW2010 vs 2003 Word 2003 is getting problems - funny characters on the screen that do not print skkuchipudi Word 4 10-28-2015 09:18 AM
Problems with Macros in MSW2010 vs 2003 Word 2013 problems with the Macros boki_s78 Word VBA 3 04-23-2014 03:30 AM
Problems with Macros in MSW2010 vs 2003 Problems with Recording Macros jekronenfeld Excel 6 09-26-2013 03:07 PM
Problems with Macros in MSW2010 vs 2003 Copy Macros from Word 2003 - Word 2007 ballj_35 Word VBA 7 05-05-2011 12:37 AM
Excel 2003 SP3 bug when running Macros EnricoVenturi Excel 0 09-06-2009 08:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:27 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