Results 1 to 14 of 14
  1. #1
    New Lounger
    Join Date
    Aug 2015
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automatic numbering VBA code - Word 2003

    Is there a way to put a space in between numbers? The automatic numbering option does not appear to have a setting that can be changed to insert a space in between, and I have not been successful in creating a style that will do this. The below code is what I have, which seems to work great, only it puts the numbers directly on top of each other, which makes the information more difficult to read. Thanks for any help you can give me. I have been working on this Macro for weeks now and am hoping to get the last couple of items worked out.

    Selection.Font.Bold = wdToggle
    Selection.TypeText text:="DIAGNOSIS: "
    Selection.Font.Bold = wdToggle
    Selection.TypeParagraph
    Selection.TypeParagraph

    With ListGalleries(wdNumberGallery).ListTemplates(1).Li stLevels(1)
    .NumberFormat = "%1."
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = InchesToPoints(0)
    .Alignment = wdListLevelAlignLeft
    .TextPosition = InchesToPoints(0.3)
    .TabPosition = InchesToPoints(0.3)
    .ResetOnHigher = 0
    .StartAt = 1
    With .Font
    .Bold = True
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .Color = wdUndefined
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Calibri"
    End With
    .LinkedStyle = ""
    End With
    ListGalleries(wdNumberGallery).ListTemplates(1).Na me = ""
    Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
    wdNumberGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
    wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior
    Selection.Fields.add Range:=Selection.Range, Type:=wdFieldEmpty, _
    PreserveFormatting:=False
    Selection.EndKey Unit:=wdLine
    Selection.TypeParagraph
    Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
    Selection.TypeParagraph

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by Atelby12 View Post
    Is there a way to put a space in between numbers? The automatic numbering option does not appear to have a setting that can be changed to insert a space in between, and I have not been successful in creating a style that will do this.
    A space between which numbers? A multilevel list can contain whatever text you like between the list-level numbers, including spaces. You can also have text before the first number in the list and after the last entry. And you don't need a macro to do it. The only limitation I'm aware of is that you're limited to about 30 characters in addition to the list-level number.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    New Lounger
    Join Date
    Aug 2015
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There are two sections in my report document that will require numbering, which is why I would like the automatic numbering function built into the Macro. Instead of the numbering starting at 2. when the Enter key is pressed, I would like that to be a blank line and the numbering start with 2. when Enter is pressed a second time so that the information is not bunched together. The below example is how I would like it to look.

    DIAGNOSIS:

    1. Acute Myocardia

    2. Renal Failure

    When attempting to record the automatic numbering code, I am not able to put in that extra space/line/enter. I was also unsuccessful when attempting to assign it to a Style. I can put in the extra line when simply typing it on the Word screen, but it takes putting in extra numbers and going back to delete ones in between before the automatic numbering function resumes in that style (hope I am making some sense here). The below example is what it currently looks like with the automatic numbering code.

    DIAGNOSIS:

    1. Acute Myocardia
    2. Renal Failure

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Spaces between paragraphs should be done by modifying the style's paragraph attributes to include a space before and/or after the paragraph.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    New Lounger
    Join Date
    Aug 2015
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, but how is that done? I do not see an option to set an additional space when creating a new style for numbering. I am clicking on New Style, Format Numbering, and choosing the style I want. The only options under Customize are Number Position, Start at 1. (or whatever number you want), Alignment Position, Tab Spacing, and Indent Position. There are no options to set an extra space in between the numbers or place an additional paragraph.

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts
    There are different types of styles. I don't use List styles because IMO they are pointless. However, I do use Paragraph styles and associate them with outline lists. It is the paragraph style that can be changed to assign the paragraph spacing you require.

    Your code in post #1 includes the following line
    .LinkedStyle = ""

    This is where you should be associating an outline level to a specific paragraph style which can carry the paragraph line spacing you want eg
    .LinkedStyle = "List Bullet"
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #7
    New Lounger
    Join Date
    Aug 2015
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I see what you are saying about the list styles and needing to alter my code to reflect the style, but wouldn't that entail other people I share the Macro with would also need to alter or create the same list style on their end? I need to write the code so that other users can install the Macro in their computers and not need to create new styles. The numbering is not a huge issue because I have been given the okay that the space does not need to be in between, but I can't believe that option was not already written into the standard styles and/or easy to add in the written code. The simplest things can be so difficult at times! Thanks for your reply and suggestions, Andrew.

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by Atelby12 View Post
    The numbering is not a huge issue because I have been given the okay that the space does not need to be in between, but I can't believe that option was not already written into the standard styles and/or easy to add in the written code.
    This whole discussion suggests you've never learnt to use Word. Just about everything in a Word document is based on Styles and creating/modifying Styles with the desired attributes is a trivial exercise, including adding a give amount of space before and/or after. Indeed, I've already given you code doing some of that ...
    http://windowssecrets.com/forums/sho...=1#post1017114
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #9
    New Lounger
    Join Date
    Aug 2015
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow, that is a condescending remark. Just because I never learned to use Styles does not mean I'm an idiot. I have worked with Word since it first came on the market and worked in WP5.1 before that time. I get the concept of styles and understand how the Normal.dot file works, but that does not mean I have ever had to create a new style and incorporate it into a Macro. I think you and I are on totally different wavelengths, as you continue to suggest I create styles. However, as mentioned previously, I do not want to create a style and incorporate it into a global Macro. I want to write the code into the Macro so that I can share it with other people. Templates are absolutely useless in my opinion, as the Macro we use automatically performs numerous functions, whereas a template would mean we would have to perform all of those additional functions manually. By the way, I wrote that Macro myself about 14 years ago with the help of others at Woody's Lounge, back when it appeared people were more tactful. While I appreciate your time and suggestions, I find your remarks very insulting. I took every one of your posts seriously and spent many hours working on the code you had provided as an example, only to find that it was not what I was trying to do. I'm going to quit writing now before I say anything further, as you have really pushed my buttons today. Please, do not bother helping me any further, as your suggestions are not what I am looking for, and you apparently feel so superior that you can say these types of things.

  10. #10
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts
    In the words of Ron Burgundy... 'Well, that escalated quickly'

    Atelby12 - if you are planning on distributing a 'global macro' then you ARE working with a template whether you want to or not. However, the template doesn't have to contain only code. From my reading of these two threads, I haven't yet seen anything that screams out for a macro since your requirements seem to be pointing to things that can be done by using a template for style and building blocks. Yes, you can do things with a macro but in general, if you can achieve the same aims by avoiding macros then that is better practice since macros can be disabled at the user's end.

    When using macros that call for styles, I always prefer to use one of the 250+ built-in styles that exist in Word since you can be sure the macro won't fail because of a missing style. List Bullet is one of those built-in styles. You might need a macro to ensure the chosen style has the right attributes but if you are using an attached template then simply refreshing the styles in one line of code is all you need (except maybe in the case of styles with an outline list element applied to it).
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  11. #11
    New Lounger
    Join Date
    Aug 2015
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Andrew Lockton View Post
    From my reading of these two threads, I haven't yet seen anything that screams out for a macro since your requirements seem to be pointing to things that can be done by using a template for style and building blocks. Yes, you can do things with a macro but in general, if you can achieve the same aims by avoiding macros then that is better practice since macros can be disabled at the user's end.
    I'm sorry, but I am obviously not getting it, which I think is due in part to the terminology. In my mind, a template is something created when the user clicks on various toolbar options and creates a document on the screen, saving it for use later (in my business, that is what we refer to as a template, whereas a Macro is more like an automated program). The Macro we use begins with prompting the user to enter the patient information, such as name, DOB, DOS, etc. Once the user has entered all of the information, their cursor is positioned in a blank field next to the title where they need to begin typing, such as History or Diagnosis. After the report has been typed, another Macro is run for the doctor's signature, which spellchecks the document, opens a log sheet saved in another folder, appends the patient information that was entered into the text boxes, saves that document and closes. The Macro then saves a copy of the report in another folder, finally pasting a copy of the same report into another document that I refer to as the "ongoing document," where all reports will be cut/pasted so that only that document and the log sheet are returned to the doctor when completed. I understand the user can cause the Macro to malfunction, but using the Macro actually helps with accuracy and saves time when you are typing 100s of medical reports per day, which is important because we do not get paid hourly and only get paid for what we type. Having said that, I have written the automatic numbering code into the Macro, as shown below.

    Code:
     With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
            .NumberFormat = "%1."
            .TrailingCharacter = wdTrailingTab
            .NumberStyle = wdListNumberStyleArabic
            .NumberPosition = InchesToPoints(0)
            .Alignment = wdListLevelAlignLeft
            .TextPosition = InchesToPoints(0.3)
            .TabPosition = InchesToPoints(0.3)
            .ResetOnHigher = 0
            .StartAt = 1
            With .Font
                .Bold = True
                .Italic = False
                .StrikeThrough = wdUndefined
                .Subscript = wdUndefined
                .Superscript = wdUndefined
                .Shadow = wdUndefined
                .Outline = wdUndefined
                .Emboss = wdUndefined
                .Engrave = wdUndefined
                .AllCaps = wdUndefined
                .Hidden = wdUndefined
                .Underline = wdUndefined
                .Color = wdUndefined
                .Size = 11
                .Animation = wdUndefined
                .DoubleStrikeThrough = wdUndefined
                .Name = "Calibri"
            End With
                .LinkedStyle = ""
    I have tried to create a new style by clicking on Format, Styles and Formatting and creating a paragraph style for the automatic numbering. I also did as you suggested and tried creating a new style by using the listed styles already available for numbering. I tried recording the steps for adding the space for automatic numbering and have even tried adding my own code into what is shown above. However, no matter what I have done, I cannot get that extra space in between the numbers. The only way I can get the extra space in between is if I am simply typing it out on the screen using Format, Bullets and Numbering, selecting the numbering option I want. When I type 1. on the screen, the automatic numbering then puts a 2. directly below. When I press Enter again, the 2. disappears, so I manually type 2., and then the automatic numbering takes over and has it spaced the way I want. I have not been able to replicate this action by trying to create a new style or use the recorder, as automatic numbering does not take over when I put in that extra space and begin with 2. again. I have looked at all of the options in the automatic numbering selection and tried various things, but there is no option to set the paragraph or spaces entered, only for indent and other unrelated things.

    Can you walk me through it step-by-step - click on Toobar, select "", etc.? I do not consider myself to be stupid, but I am obviously not understanding, which is extremely frustrating on my part because I know it is most likely one simple thing I am missing.

    I appreciate your time and patience, as well as not saying things like "did you read my post, I have already told you that..."

  12. #12
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    The reason you're 'not getting it' is that you're wedded to doing something in a way that we keep telling you is fundamentally flawed. The fact you've managed to use Word as long as you have without coming to grips with Templates and Styles really does show a complete disinterest in how Word works. Do you clients a favour: pull out of this project and refer them to someone who is competent. Do yourself a favour: learn to use Word...
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  13. #13
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    I agree with Andrew and Paul.

    You need to step back. Learn to use Styles. What you want to accomplish should not require a macro and using a macro may make things harder for both you and your users. You are trying to reinvent the wheel rather that using the one that comes with your vehicle.

    Styles are at the very heart of Word. Trying to use Word without understanding and using styles is like pushing on a string. I resisted learning and using styles for years and now regret every day of those years because although that string was still very hard to push, it kept getting longer and longer, and had some very important projects tied to it! Once you understand styles and the Word concept of organizing things into Chinese boxes everything falls into place and instead of pushing a string, you can push a button that turns on the very powerful text processing machine known as Microsoft Word and it will start doing your work for you instead of running around behind you trying to undo what you thought you just did.

    Here are some links that can help you.




    Once you have a grip on how Styles work, but not until then, you can tackle numbering.
    Controlling numbering in Word by Shauna Kelly
    Charles Kyle Kenyon
    Madison, Wisconsin

  14. The Following User Says Thank You to Charles Kenyon For This Useful Post:

    RetiredGeek (2015-08-22)

  15. #14
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Learn to use the tools you have before re-inventing the tools you have

    Hi
    You have been given excellent advice by some of the most knowledgeable people in the sphere.

    Take 10 deep breaths and have a coffee or whatever.

    Power in Word is derived from templates and styles.
    Styles in word existed before the Windows platform. Pre WordPerfect 5.1
    Templates are absolutely useless in my opinion, as the Macro we use automatically performs numerous functions, whereas a template would mean we would have to perform all of those additional functions manually.
    You seem to be in the mindset of WP5.1. That was an excellent and fast word processor. Macros were a huge time saver. Nevertheless it disappeared.
    You can not use Word without using templates.

    Nobody ever said that the numbering schemes were easy. Managing list galleries and list formats takes some time and effort. Learn to use styles.

    If the world is telling you something that you disagree with then that does not mean that the world is wrong.
    I would like that to be a blank line and the numbering start with 2.
    Don't use a blank line. Instead increase the space before or after paragraph. This is part of the style definition.

    You will find this in the Modify style dialog. Bottom left is the format button. One item in the drop list is "paragraph".

    You have heard it before. Learn to use styles. It will save you and your company time in the end.

    G
    Last edited by geofrichardson; 2015-08-23 at 00:09.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •