PDA

View Full Version : Trouble Writing a Macro: Changing a Numbered List to a Style



Writeforaliv
03-11-2014, 07:29 AM
Hello,

I am new to programming and struggling with what may be a very simple task. I am trying to write a macro that will automatically change a numerical list into one of the styles I created in my document template. Why I've been successful in creating a very lengthy macro using the Macro Recording feature in Word, I would like to create something more robust. Can anyone provide me with some brief instruction, or advice on where I could seek this information?

Thanks in advance!

fumei
03-11-2014, 01:43 PM
Without seeing the code you have already it is hard to know what to suggest. Some general suggestions may be:

avoid using Selection where possible
use objects where possible
avoid extended multiple If-Then statements

Writeforaliv
03-12-2014, 04:11 AM
Thanks for responding.

Yes, my macro definitely uses Selection. What would you recommend using instead? I've pasted a snippet from my macro below; it doesn't change at all because I just need it to update the numerical list into the desired style. Then, I need it to shift the text that corresponds to each instance of the now generated style below it.

Selection.Paragraphs(1).SelectNumber
Selection.Style = ActiveDocument.Styles("Slide Number")
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.TypeParagraph
Selection.Paragraphs(1).SelectNumber
Selection.TypeBackspace
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.Paragraphs(1).SelectNumber
Selection.Style = ActiveDocument.Styles("Slide Number")
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.Paragraphs(1).SelectNumber
Selection.TypeBackspace
Selection.MoveDown Unit:=wdLine, Count:=2