如下代碼是從微軟幫助里面拷貝出來的,運行總是在第一個表格建立后出現如下問題(出現問題行標有10001):
“被呼叫方拒絕接收呼叫。 (例外來自 HRESULT:0x80010001 (RPC_E_CALL_REJECTED))”
即時視窗出現:在 System.Runtime.InteropServices.COMException 中第一次偶然出現的“ ”型別的例外
請教高手,指點原因。
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph
Dim oPara3 As Word.Paragraph, oPara4 As Word.Paragraph
'建立一個檔案
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
'插入一個段落
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "1、輸入引數"
oPara1.Range.Font.Bold = True
oPara1.Format.SpaceAfter = 6
oPara1.Range.InsertParagraphAfter()
'插入一個段落
oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara2.Range.Text = "1.1 基本引數"
oPara2.Range.Font.Bold = False
oPara2.Format.SpaceAfter = 6
oPara2.Range.InsertParagraphAfter()
'插入一個2x6的表格,
Dim c As Integer
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, 2, 6)
oTable.Range.ParagraphFormat.SpaceAfter = 6
With oTable
.Cell(1, 1).Range.Text = "氣"
.Cell(1, 2).Range.Text = "水"
.Cell(1, 3).Range.Text = "管壁"
.Cell(1, 4).Range.Text = "地溫"
.Cell(1, 5).Range.Text = "預測"
.Cell(1, 6).Range.Text = "預測"
.Cell(2, 1).Range.Text = sinGasRelativeDensity
.Cell(2, 2).Range.Text = sinWaterDensity
.Cell(2, 3).Range.Text = sinConFlowPreRoughness
.Cell(2, 4).Range.Text = sinConFlowTempGr
.Cell(2, 5).Range.Text = sinStaticP
.Cell(2, 6).Range.Text = sinStaticT
oTable.Rows.Item(1).Range.Font.Bold = True
oTable.Rows.Item(1).Range.Font.Italic = False
.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle
.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle
End With
'插入一個段落
oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range) ‘10001
oPara3.Range.Text = "1.2產量資料"
oPara3.Range.Font.Bold = False
oPara3.Format.SpaceAfter = 24
oPara3.Range.InsertParagraphAfter()
uj5u.com熱心網友回復:
沒有人回答啊轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/113937.html
標籤:資源
下一篇:關于寫順序檔案的問題
