2013-06-19 51 views
0

好的,基本上,我們在Word 2007的啓用宏的模板中有幾個獨特的部分,對於每個部分,我們有2個表單標準的條目,然後大約有20個可選條目全部處理通過自動圖文集。模板和自動圖文集詞條之間的格式相同,我想在添加條目時自動編號條目(通過用戶鍵入自動圖文集關鍵詞或點擊功能區上的按鈕來插入條目)。 有沒有簡單的方法來做到這一點? 這裏就是這些(編號)項中的一個處理的代碼塊,什麼我試圖實現,因爲從其他論壇的其他建議(不能在這裏找到有用的東西)編號方案:是否有一種「優雅」的方式來在Word 2007宏(VBA)中實施自動編號?

Case "cboFF" 
         SetMargins 0, 1, 1 
         Selection.ParagraphFormat.Space1 
         Selection.Text = "FINDINGS OF FACT" & vbLf 
         Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter 
         Selection.Font.Bold = True 
         Selection.Font.Underline = wdUnderlineSingle 
         Selection.Collapse (wdCollapseEnd) 
         Selection.Text = vbLf 
         Selection.ParagraphFormat.SpaceAfter = 6 
         Selection.Collapse (wdCollapseEnd) 
         Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify 
         Selection.Font.Underline = wdUnderlineNone 
         Selection.Font.Bold = False 
         SetMargins 0, 1, 1 
         'With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1) 
         '.NumberFormat = "%1." 
         '.TrailingCharacter = wdTrailingTab 
         '.NumberStyle = wdListNumberStyleNone 
         '.NumberPosition = InchesToPoints(0.5) 
         '.Alignment = wdListLevelAlignLeft 
         '.TextPosition = InchesToPoints(0.5) 
         '.ResetOnHigher = 0 
         '.StartAt = 1 
         'AutoNumberOnFOF 
         Selection.Text = "On " & strDateFOF & ", an industrial appeals judge certified that the parties agreed to include the Jurisdictional History in the Board record solely for jurisdictional purposes." & vbLf 
         Selection.ParagraphFormat.SpaceAfter = 6 
         Selection.Collapse (wdCollapseEnd) 
         Select Case strCaseCategory 
          Case "IND", "IND SELF-I" 
           If frmIIOD.optII.Value = True Then 
            Selection.Text = "II-FF" 
            Selection.Range.InsertAutoText 
            Selection.Collapse (wdCollapseEnd) 
            Selection.Text = vbLf 
            Selection.ParagraphFormat.SpaceAfter = 6 
            Selection.Collapse (wdCollapseEnd) 
            GoToEnd 
           End If 
           If frmIIOD.optOD.Value = True Then 
            Selection.Text = "OD-FF" 
            Selection.Range.InsertAutoText 
            Selection.Collapse (wdCollapseEnd) 
            Selection.Text = vbLf 
            Selection.ParagraphFormat.SpaceAfter = 6 
            Selection.Collapse (wdCollapseEnd) 
            GoToEnd 
           End If 
           If frmIIOD.optNotNeeded.Value = True Then 
            Selection.Text = vbLf 
            Selection.ParagraphFormat.SpaceAfter = 6 
            Selection.Collapse (wdCollapseEnd) 
           End If 
          Case Else 
           'Do Nothing 
         End Select 

任何建設性的意見將非常感謝,以幫助解決這個問題。我對整體編程還很陌生,我的大部分經驗都來自C#和Java。

編輯:文檔的結構基本上是一組包含法律文本的逐項列表,當用戶上傳過程經歷各個階段時,由用戶更新。在最後兩節的每一節中,逐項列表都需要遵循特定的編號方案(編號爲.5「,文本爲1」,右邊的標籤爲1「),它不是Word 2007的本機編號。每個編號方案都有一個粗體標題自動圖文集詞條將根據用戶的需要添加,文檔的其餘部分從我們的數據庫中提取信息幷包含文檔所需的合法用語 如果我只是想那麼我可以完成這個。

+0

您能否將鏈接附加到您的文檔以更好地理解文檔結構? –

回答

0

我已經想出了我自己的解決方案,問題是試圖在第二行插入一個自動圖文集詞條因爲它讀取整行並認爲它是一個自動圖文集詞條,而不是僅讀取ii-ff或od-ff,它讀取的是1. ii-ff,這不是有效的自動圖文集輸入(按名稱)。

    Case "cboFF" 
         SetMargins 0, 1, 1 
         Selection.ParagraphFormat.Space1 
         Selection.Text = "FINDINGS OF FACT" & vbLf 
         Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter 
         Selection.Font.Bold = True 
         Selection.Font.Underline = wdUnderlineSingle 
         Selection.Collapse (wdCollapseEnd) 
         Selection.Text = vbLf 
         Selection.ParagraphFormat.SpaceAfter = 6 
         Selection.Collapse (wdCollapseEnd) 
         Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify 
         Selection.Font.Underline = wdUnderlineNone 
         Selection.Font.Bold = False 
         SetMargins -0.5, 1, 1 
         'AutoNumberOn 
         Selection.Text = "1." & vbTab & "On " & strDateFOF & strEntry1 & vbLf 
         Selection.ParagraphFormat.SpaceAfter = 6 
         Selection.Collapse (wdCollapseEnd) 
         Select Case strCaseCategory 
          Case "IND", "IND SELF-I" 
           If frmIIOD.optII.Value = True Then 
            Selection.Text = "2." & vbTab & strIIEntry & vbLf 
            Selection.ParagraphFormat.SpaceAfter = 6 
            Selection.Collapse (wdCollapseEnd) 
            Selection.Text = "3." & vbTab & "" & vbLf 
            Selection.Collapse (wdCollapseEnd) 
           End If 
           If frmIIOD.optOD.Value = True Then 
            Selection.Text = "2." & vbTab & strODEntry & vbLf 
            Selection.Text = "3." & vbTab & "" & vbLf 
            Selection.Collapse (wdCollapseEnd) 
           End If 
           If frmIIOD.optNotNeeded.Value = True Then 
            Selection.Text = "2." & vbTab & "" & vbLf 
            Selection.ParagraphFormat.SpaceAfter = 6 
            Selection.Collapse (wdCollapseEnd) 
           End If 
          Case Else 
           'Do Nothing 
         End Select 

這使得對空行插入自動圖文集詞條,並繼續預格式化的命名系統,是不是當地的Word 2007中現在我只需要弄清楚內higlight特定單詞的最簡單方法插入的選擇。應該不會太差:

'set array of text entries (6) 
    'begin loop 
    'find and highlight entry(i) 
    'end loop 
相關問題