close

參考來源:http://www.blueshop.com.tw/board/show.asp?subcde=BRD20070122095530IPZ&fumcde=FUM200501271723350KG

所有的設定大部份軟體會預設,只要擷取想要自行設定的部份即可.

Dim WordObj                              As New Word.Application()

With WordObj                                 

      .Visible = True                                
     .Documents.Open("檔案路徑") '<----------------------------------------開啟 .DOC檔   

   '設定頁首頁尾文字   
    .Selection.Sections(1).Headers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text = "首頁文字" 
    .Selection.Sections(1).Footers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text = "頁尾文字"

    .Selection.Font.Size = 20
    .Selection.Font.Name = "標楷體"
    .Selection.ParagraphFormat.Alignment = 1
    .Selection.TypeText ("rwarwa")
    .Selection.Font.Color = vbRed
    .Selection.Font.Bold = True
    .Selection.TypeText ("(rwwwww)")
    .Selection.TypeParagraph

    .ActiveWindow.View.Type = WdViewType.wdPrintView   '設定版面顯示方式

   '設定表格中要跨頁標題重複的部份(沒有合併或分割表格時)               

     .ActiveDocument.Tables(1).Rows(1).HeadingFormat = True '選擇表格要重複部份的列(第一列) 
   .Selection.Rows.HeadingFormat=Word.WdConstants.wdToggle '設定所選擇完成的部份並設定跨頁標題重複

   '設定表格中要跨頁標題重複的部份(有合併或分割表格時) 
  .ActiveDocument.Tables(2).Cell(1, 1).Select()  '先選擇表格中(文件中的第二個表格)要重複部份旳開頭儲存格 
  .Selection.MoveRight(WdUnits.wdCharacter, 15)  '向右位移到表格中要重複部份的結尾,以字元為單位 
  .Selection.Rows.HeadingFormat=Word.WdConstants.wdToggle '設定所選擇完成的部份並設定跨頁標題重複

  With ActiveDocument.PageSetup '<-------------------------整份文件

     .TopMargin = objAppEdit.CentimetersToPoints(1)       '設定上邊界

     .BottomMargin = objAppEdit.CentimetersToPoints(1)  '設定下邊界

     .LeftMargin = objAppEdit.CentimetersToPoints(1)       '設定左邊界

     .RightMargin = objAppEdit.CentimetersToPoints(1)     '設定右邊界

     .LineNumbering.Active = False

     .Orientation = wdOrientPortrait

     .Gutter = CentimetersToPoints(0)

     .HeaderDistance = CentimetersToPoints(0.8)

     .FooterDistance = CentimetersToPoints(0.8)

     .PageWidth = CentimetersToPoints(21)       '<---A4 Size Width

     .PageHeight = CentimetersToPoints(29.7)   '<---A4 Size Height

     .FirstPageTray = wdPrinterDefaultBin

     .OtherPagesTray = wdPrinterDefaultBin

     .SectionStart = wdSectionNewPage

     .OddAndEvenPagesHeaderFooter = False

     .DifferentFirstPageHeaderFooter = True

     .VerticalAlignment = wdAlignVerticalTop

     .SuppressEndnotes = False

     .MirrorMargins = False

     .TwoPagesOnOne = True                   '<------------------單面雙頁

     .BookFoldPrinting = False

     .BookFoldRevPrinting = False

     .BookFoldPrintingSheets = 1

     .GutterPos = wdGutterPosTop

     .LayoutMode = wdLayoutModeDefault

     .ActiveDocument.PageSetup.Orientation = 1      '而且要擺在最後面喔~ 不然設定會被蓋掉~原因不明 ,0 是 直向 ,1 是 橫向

   End With

  .ActiveDocument.Save()                                  '儲存文件

  .ActiveDocument.Close()                                 '關閉文件

.Quit()                                 

End With                               

WordObj = Nothing

arrow
arrow
    全站熱搜

    就是要紅 發表在 痞客邦 留言(0) 人氣()