我目前正在編寫此應用程序來打印並創建一個報告給一個新的Word文檔。但是,我遇到了一個絆腳石。當我將數據寫入這個新的Microsoft Word文檔時,他們以任何方式檢查它是否有新頁面,例如報告佔用了10頁,他們是否檢查應用程序何時開始寫入新頁面?操縱微軟字
代碼:
Dim objWord
As Word.Application
Dim objDoc As Word.Document
Dim objTable As Word.Table
Dim r As Integer, c As Integer
Dim pages1 As Pages
Dim pagecountbefore As Integer
objWord = CreateObject("Word.Application")
objWord.Visible = True
objDoc = objWord.Documents.Add
pagecountbefore = pages1.Count
objTable = objDoc.Tables.Add(objDoc.Bookmarks.Item("\endofdoc").Range, 3, 5)
objTable.Range.ParagraphFormat.SpaceAfter = 6
For r = 1 To 1000
For c = 1 To 5
If r = 1 Then
Select Case c
Case "1"
objTable.Cell(r, c).Range.Text = "PCI DSS Requirements "
Case "2"
objTable.Cell(r, c).Range.Text = "Testing Procedures "
Case "3"
objTable.Cell(r, c).Range.Text = "In Place"
Case "4"
objTable.Cell(r, c).Range.Text = "Not in Place"
Case "5"
objTable.Cell(r, c).Range.Text = "Target Date/ Comments"
End Select
Else
If pagecountbefore<pages1.Count Then
pagecountbefore = pages1.Count
Select Case c
Case "1"
objTable.Cell(r, c).Range.Text = "PCI DSS Requirements "
Case "2"
objTable.Cell(r, c).Range.Text = "Testing Procedures "
Case "3"
objTable.Cell(r, c).Range.Text = "In Place"
Case "4"
objTable.Cell(r, c).Range.Text = "Not in Place"
Case "5"
objTable.Cell(r, c).Range.Text = "Target Date/Comments"
End Select
Else
'print resultrs from database
End If
End If
Next
Next
我很好奇的頂部。你爲什麼關心網頁?爲什麼不讓Word處理分頁? –
因爲我試圖通過一個Windows應用程序模擬我公司的這份報告。每個新的頁面都有表格標題,所以我想知道我該如何做到這一點 –
我的意思是Word可以設置爲做頁眉和頁腳,所以你不需要知道。 –