Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Park City, Utah
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Custom Numbering Macro (2003/SP1)

    This seems so simple, but I am messing something(s) up. I want a macro that will create a custom numbered list at the end of a document. These will be for the carbon copies the documents go to and I am using |x|: for the numbering system for markers because another macro will search the document for the |x|: and copy the rest of the line and print a notation that that is who the copy is for. So I want a list at the bottom that looks like:

    |1|: DOCTOR NAME 1
    |2|: DOCTOR NAME 2
    and so on up to 5 copy names.

    The numbers should be inserted sequentially based on whether they are already there, i.e., search for |1|: and if it is not there, go to the bottom of the document and insert it and stop. If it is there, go to the bottom fo the document, put in a new line and insert |2|: and then stop and so on for up to 5 copies.

    My brain is dead apparently...

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Custom Numbering Macro (2003/SP1)

    Can you try to explain more clearly? What exactly do the markers in the body of the document look like? |x| or |3|? Perhaps you could attach a small demo document (with dummy text).

  3. #3
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Park City, Utah
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Custom Numbering Macro (2003/SP1)

    Yes, sorry, the format will contain the number, I used x as a placeholder.

    These are medical documents that the user is transcribing from dictation. If the dictator says, "please send a copy to doctor Wilson" the user will run the macro which will look for |1|: and if it is not there, go to the bottom, enter a new line and insert:
    |1|: DOCTOR WILSON MD

    Each time the dictator states, "send a copy to doctor so-and-so," the user launches the macro which searches for the numbers between bars and inserts a new line and the next sequential number, so for the above example, the last 2 lines of the body of the document would be:

    |1|: DOCTOR WILSON MD
    |2|: DOCTOR SO-AND-SO MD

    The goal is that we are not using bookmarks or fields which can accidentally be deleted because at the time of printing, the printing macro searches for the |1|:, copies the name following it and prints a tag line in the footer: ,Copy for DOCTOR WILSON MD, then does the same for |2|:, |3|: up to 5 copies.

    If you understand this process and can recommend a better way to do it, none of the coding has been done yet, not even for the print macro, so I am open to suggestions.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Custom Numbering Macro (2003/SP1)

    That still seems tricky - the user could easily mess up the lines at the end. I would do it differently:

    1) Run a macro once to create 5 custom document properties to hold the names of the doctors (it could be more, if needed, and the number could be made variable too, if needed):

    Sub InitDoctors()
    Dim i As Integer

    For i = 1 To 5
    ActiveDocument.CustomDocumentProperties.Add Name:="Doctor" & i, _
    LinkToContent:=False, Type:=msoPropertyTypeString, Value:=""
    Next i
    End Sub

    2) Each time the dictator says "Please send a copy to ...", the user runs the following macro (assign it to a toolbar button and/or keyboard shortcut for ease of use):

    Sub AddDoctor()
    Dim strDoctor As String
    Dim i As Integer

    strDoctor = InputBox("Send to whom?")
    If strDoctor = "" Then
    Exit Sub
    End If

    For i = 1 To 5
    If ActiveDocument.CustomDocumentProperties("Doctor" & i) = "" Then
    ActiveDocument.CustomDocumentProperties("Doctor" & i) = strDoctor
    Exit For
    End If
    Next i

    If i = 6 Then
    MsgBox "Sorry, all five names are already in use.", vbExclamation
    End If
    End Sub

    3) To print the copies for the doctors, run this macro:

    Sub PrintCopies()
    Dim i As Integer

    For i = 1 To 5
    If ActiveDocument.CustomDocumentProperties("Doctor" & i) = "" Then
    Exit For
    End If
    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range.Text = _
    "Copy for " & ActiveDocument.CustomDocumentProperties("Doctor" & i)
    ActiveDocument.PrintOut
    Next i

    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range.Delete
    End Sub

    4) To view currently added doctors:

    Sub ListDoctors()
    Dim i As Integer
    Dim strDoctors As String

    For i = 1 To 5
    If ActiveDocument.CustomDocumentProperties("Doctor" & i) = "" Then
    Exit For
    End If
    strDoctors = strDoctors & ActiveDocument.CustomDocumentProperties("Doctor" & i) & vbCrLf
    Next i

    MsgBox strDoctors
    End Sub

    5) You can edit the list in File | Properties, Custom tab.

  5. #5
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Park City, Utah
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Custom Numbering Macro (2003/SP1)

    Thank you, Hans, this is extremely helfpul. I was planning to use custom doc properties originally, but have no experience using that feature and also don't know how to manage arrays very well, but with your help, I am learning.

Posting Permissions

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