none
Yet another Linked list question RRS feed

  • Question

  • Hi all

    After getting everything to work properly, the user decided that they couldn't live with the fact that some cells had more space after the Question/Response combo (the other cell had a 'bigger' text selection), so we're back to printing within the Document only. 

    They also wanted the linked list to be "a) " instead of "A.  ".  Ok, says I.  So I go to the macro recorder and create a macro using the "a)" and the only change it made to the code was to the  .NumberStyle setting it to wdListNumberStyleLowercaseLetter instead of wdListNumberStyleUppercaseLetter.

    Now, the problems:

    When I run the code, I get "a.  ", not the "a) " that I want.

    Also, I can't seem to get to the 'bottom' of my Selection so that when I go to print the next question, the formatting is being applied to the last item in the linked list.

    Current code being used:  (anything following a '&&' or '*' is a comment and has been put in for explanation)

    oApp = Createobject("word.Application")
    ** Create New Document
    oDoc = oApp.Documents.Add()
    oDoc.TextLineEnding = 1  && wdCROnly

    oApp.ActiveDocument.PageSetup.TopMargin = oApp.InchesToPoints(1)
    oApp.ActiveDocument.PageSetup.BottomMargin = oApp.InchesToPoints(1)
    oApp.ActiveDocument.PageSetup.rightMargin = oApp.InchesToPoints(1)
    oApp.ActiveDocument.PageSetup.leftMargin = oApp.InchesToPoints(1)

    * Set up Doc Footer
    oApp.ActiveDocument.Sections[1].footers[1].pagenumbers.Add()
    oApp.ActiveDocument.Sections[1].footers[1].pagenumbers[1].Alignment = 1
    * Set up header
    rHdr = oApp.ActiveDocument.Sections.First.Headers.Item[1].Range
    rHdr.Text = ""
    rHdr.Font.Name = "Courier New"
    rHdr.Font.Size = 10.5
    rHdr.InsertAfter("ENGLISH COMPREHENSION LEVEL EXAMINATION" + CR)
    rHdr.InsertAfter("Form " + m.testnum + CR)

    *Set Document Font name And size
    DocRange = oDoc.Range()
    DocRange.Font.Name = 'Courier New'
    DocRange.Font.Size = 10.5
    DocRange.ParagraphFormat.LineSpacingRule = 0  && wdLineSpaceSingle
    DocRange.ParagraphFormat.KeepTogether = .T.
    DocRange.ParagraphFormat.KeepWithNext = .T.
    ** go to beginning of section
    DocRange.Text = ""
    DocRange.InsertAfter(CR + "PART I - LISTENING" + CR)
    DocRange.InsertAfter("Directions for items 1-56.  You will hear statements or ")
    DocRange.InsertAfter("questions on the tape.  Select the best answer and mark your ")
    DocRange.InsertAfter("answer sheet, a, b, c, or d.  DO NOT WRITE ON THE TEST BOOKLET." + CR)
    ** go to bottom of section
    DocRange.Collapse(0)
    oDoc.Sections.Add()
    oDoc.PageSetup.SectionStart = 0 && Continuous
    SectionCnt = oDoc.Sections.Count
    *oSec = oDoc.Sections[SectionCnt].Range
    oSec = oDoc.Paragraphs.Last.Range
    nRow = 0
    ** Set "Last Page"
    *mcurpage = oSec.Range.Information(3)
    maxRow = 0
    HoldRow = 0
    ShortSection = .F.

    oApp.Visible = .t.

    ** print cat 40 - print next set of instructions, print cat 41,
    Scan While cat < '50'
       mcat = cat
       if !bof()   &&if not beginning of file
         skip -1  && go back one in the cursor
       endif
       Scan While cat = mcat  &&mcat has been set above this code
          nRow = nRow + 1
          Store '' To fblock, line1, line2, line3, line4, line5
          ** set up first line (Question)

          If Empty(stem)    && just the responses
             line1 = Iif(qstnum < 10,' ' + Alltrim(Str(qstnum)), Alltrim(Str(qstnum)));
                + '.  _____' + CR
          Else
             line1 = Iif(qstnum < 10,' ' + Alltrim(Str(qstnum)), Alltrim(Str(qstnum)));
                + '.  ' + Alltrim(stem) + CR
          Endif
          oSec.Paragraphs.LeftIndent = oApp.InchestoPoints(.41)
          oSec.paragraphs.FirstLineIndent = oApp.InchestoPoints(-.42)
          oSec.ParagraphFormat.linespacing = 10
          oSec.InsertAfter(CR + line1)
          ** the following moves the cursor to the end of the line just printed
          oSec.Collapse(0)
          ** Now we set up the bulleted list for the responses
          With oApp.ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
             .NumberFormat = "%1."
             .TrailingCharacter = wdTrailingTab
             .NumberStyle = wdListNumberStyleLowercaseLetter
             .NumberPosition = oApp.InchesToPoints(0.43)
             .Alignment = wdListLevelAlignLeft
             .TextPosition = oApp.InchesToPoints(0.63)
             .ResetOnHigher = 0
             .StartAt = 1
             .LinkedStyle = ""
          Endwith
          oApp.ListGalleries(wdNumberGallery).ListTemplates(1).Name = ""
          oSec.ListFormat.ApplyListTemplateWithLevel(oApp.ListGalleries(wdNumberGallery).ListTemplates(1),.F., wdListApplyToThisPointForward, 2)
          oSec.InsertAfter(Alltrim(respa) + CR)
          oSec.InsertAfter(Alltrim(respb) + CR)
          oSec.InsertAfter(Alltrim(respc) + CR)
          oSec.InsertAfter(Alltrim(respd))
          oSec.Collapse(0)
       Endscan &&cat = mcat

    Any help/suggestions?

     

     

    Friday, January 13, 2012 7:35 PM

Answers

  • Hi Dorriss,

    My first thought is that you seem to have a lot of code doing what's usually done best via the use of a template with appropriately-defined Styles. Is there a reason you can't simply create a template with the desired setup and, when you create a new document, use that template?

    As for the 'a.' instead of 'a)', that's because you're using '.NumberFormat = "%1."' instead of '.NumberFormat = "%1)"'.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Edited by macropodMVP Saturday, January 14, 2012 1:23 AM
    • Marked as answer by Bruce Song Wednesday, February 1, 2012 9:46 AM
    Saturday, January 14, 2012 1:01 AM