locked
Help needed with Macro writing - Word2003 vs Word2010 RRS feed

  • Question

  • 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

    Thursday, August 27, 2015 5:39 PM

All replies

  • The same macro you used in Word 2003 should work in Word 2010. That said, the process you describe in your first paragraph could probably be done via Find/Replace, with or without a macro. However, differences in page layout between Word 2003 & 2010, due to changes in printer drivers, could cause things to shift from where they were before and changing from the doc format to docx could introduce even more layout changes.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, August 28, 2015 5:09 AM
  • Thanks for your reply.

    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

    Thursday, September 3, 2015 6:33 PM
  • There is nothing about your macro that would account for any differences in behaviour. The functions used perform exactly the same in all Word versions. If you could upload a document to a file hosting site (e.g. OneDrive) and post a link here showing what you're working with and what you want the outcome to be, it would be easier to understand what the issue might be.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, September 4, 2015 8:06 AM
  • Hi,

    As this question is about macro, I suggest this customer post the question in the Word for Developers forum for further assistance:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev

    Regards,

    Melon Chen
    TechNet Community Support


    It's recommended to download and install Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office programs. Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, September 7, 2015 7:54 AM
  • As this question is about macro, I suggest this customer post the question in the Word for Developers forum for further assistance

    I'm sure there are plenty of people who can answer the question here. I don't know what you think would be achieved by having the OP post the same question in another forum just so I can answer it there...



    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, September 7, 2015 9:36 AM