Results 1 to 2 of 2
  1. #1
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts

    VBA word: how to design subroutin

    I have a repetitive task of printing 10 lines.
    Each line includes text, drop down list, and optional another drop down list.
    I wrote the following code per line, that does the job (at least I think so):
    Code:
    Selection.TypeText Text:="The Vital Capacity is:" & vbTab
    
    Dim objcc1 As ContentControl
    Set objcc1 = Selection.Range.ContentControls.Add(wdContentControlDropdownList)
    
        objcc1.DropdownListEntries.Add "Normal"
        objcc1.DropdownListEntries.Add "Low Normal"
        objcc1.DropdownListEntries.Add "Increased"
        objcc1.DropdownListEntries.Add "Decreased"
    
        Selection.MoveDown Unit:=wdLine, Count:=1
        Selection.TypeParagraph
    This code is to be repeated 10 times, not a proper coding style.

    i was repeating to make a subroutine, something like:
    Code:
    Sub PrintLine(mytext As Integer, obj As ContentControl)
    
    End Sub
    The idea is to define the objcc1,objcc2 etc outside the subroutine, but the problem I see is that the SET line is also printing it, and the whole idea was to build the structure outside, and send it to the SUB for printing.
    Any idea how can I just declare and assign the drop down outside the SUB, and only printing it inside the SUB?
    And the first thing I saw is that if

  2. #2
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts
    You need to be in a different forum. This one is about using Word Processing programs (end user) not development. See: The VBA forum.
    Charles Kyle Kenyon
    Madison, Wisconsin

Tags for this Thread

Posting Permissions

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