• macro to specify number (VBA Office XP)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » macro to specify number (VBA Office XP)

    Author
    Topic
    #403272

    I hope I can explain this properly. I have one page coversheet for legal exhibits. I have been asked to create a macro that asks the user how many of these sheets needs to be created and then inserts that many pages into the document and numbers each one (exhibit 1, exhibit 2, etc). I also need to ask the user if they want the exhibits numbered 1,2,3 or a,b,c. I know that I need to use SEQ codes for this but can’t get my head around where to start or what the code needs to be like. Can anyone help????

    Viewing 1 reply thread
    Author
    Replies
    • #810055

      What if you cheat a bit… Put the text in the header, use a page number code for the exhibit number, and just insert page breaks for each desired page. The only hard part is that you need to insert a switch into the page number code that tells it whether to use regular numbers or regular letters. Or you could save one of each as an AutoText, and insert the AutoText desired by the user.

      But… to use SEQ fields, perhaps something like this:

      Sub MakePages()
      Dim intNumExhibits As Integer, strNumStyle As String, intCounter As Integer
      intNumExhibits = CInt(InputBox("How many exhibit cover sheets would you like?"))
      If MsgBox("Use letters instead of numbers?", vbYesNo) = vbYes Then
          strNumStyle = "* Alphabetic"
      Else
          strNumStyle = "* Arabic"
      End If
      For intCounter = 1 To intNumExhibits
          With Selection
              .TypeText "Exhibit "
              .Fields.Add .Range, wdFieldSequence, "Exhibit " & strNumStyle
              If intCounter < intNumExhibits Then
                  .InsertBreak wdPageBreak
              End If
          End With
      Next
      End Sub

      When I try this in Word 2002, I get a “bonk” noise after the InputBox, but I can’t tell what’s causing it. Hmmm… maybe specifying an icon for the MsgBox would fix that.

      • #810716

        Thanks. That gave me the basis I needed. I ended up using a collection of auto text entries to build a series of documents based on choices on a userform, but this was the basis of the code. Thanks!!!!

      • #810717

        Thanks. That gave me the basis I needed. I ended up using a collection of auto text entries to build a series of documents based on choices on a userform, but this was the basis of the code. Thanks!!!!

    • #810056

      What if you cheat a bit… Put the text in the header, use a page number code for the exhibit number, and just insert page breaks for each desired page. The only hard part is that you need to insert a switch into the page number code that tells it whether to use regular numbers or regular letters. Or you could save one of each as an AutoText, and insert the AutoText desired by the user.

      But… to use SEQ fields, perhaps something like this:

      Sub MakePages()
      Dim intNumExhibits As Integer, strNumStyle As String, intCounter As Integer
      intNumExhibits = CInt(InputBox("How many exhibit cover sheets would you like?"))
      If MsgBox("Use letters instead of numbers?", vbYesNo) = vbYes Then
          strNumStyle = "* Alphabetic"
      Else
          strNumStyle = "* Arabic"
      End If
      For intCounter = 1 To intNumExhibits
          With Selection
              .TypeText "Exhibit "
              .Fields.Add .Range, wdFieldSequence, "Exhibit " & strNumStyle
              If intCounter < intNumExhibits Then
                  .InsertBreak wdPageBreak
              End If
          End With
      Next
      End Sub

      When I try this in Word 2002, I get a “bonk” noise after the InputBox, but I can’t tell what’s causing it. Hmmm… maybe specifying an icon for the MsgBox would fix that.

    Viewing 1 reply thread
    Reply To: macro to specify number (VBA Office XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: