救命啊 ????vb调用word的问题,

wzxiaodu 2002-10-04 10:18:53
本人学vb调用word,
在某些机子上出现老是以下错误,“
实时错误 '-2147417846 (8001010a)':
自动化错误

是运行到Set oWord = CreateObject("Word.Application")是错误的
而在某些机子上又正确,通过了
愁眉莫展啊,望大虾解疑??
原代码抄自网络,
代码如下::
...全文
63 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzxiaodu 2002-10-11
  • 打赏
  • 举报
回复
问题依然存在,哎
wlk 2002-10-11
  • 打赏
  • 举报
回复
不是病毒原因.

给VB打补丁.
或者在能打开的机器上打一个安装包,然后在你机器上安装,安装前先重新启动机器记住,最好不要运行任何程序,这样一般都行,我以前一直碰到这一问题.

打包时有一个数据文件必须打上,是数据更新包,大约22MB左右
lou_df 2002-10-11
  • 打赏
  • 举报
回复
重装 word 。
qyyayong 2002-10-11
  • 打赏
  • 举报
回复
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Command1_Click()

Dim bb

Text1.Text = bb
Call ShellExecute(hwnd, "Open", bb, "", App.Path, 1)
BB就是那个WORD的路径试试就可以了,
baimanixi 2002-10-04
  • 打赏
  • 举报
回复
VB调用word不用那么麻烦了,直接加入一个microsoft word组件就可以了,用你的ole控件,是不是更好用?!
wangbin_CSDN 2002-10-04
  • 打赏
  • 举报
回复
有病毒把word破坏那,我遇见过!
WizardBear 2002-10-04
  • 打赏
  • 举报
回复
建议你多找几台机器试试不同环境,

另外,杀杀毒
wzxiaodu 2002-10-04
  • 打赏
  • 举报
回复
这是上面问题的原代码
以下代码抄自网络:
******************************
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
Dim oRng As Word.Range
Dim oShape As Word.InlineShape
Dim oChart As Object
Dim Pos as Double

'Start Word and open the document template.
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oDoc = oWord.Documents.Add

'Insert a paragraph at the beginning of the document.
Set oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "Heading 1"
oPara1.Range.Font.Bold = True
oPara1.Format.SpaceAfter = 24 '24 pt spacing after paragraph.
oPara1.Range.InsertParagraphAfter

'Insert a paragraph at the end of the document.
'** \endofdoc is a predefined bookmark.
Set oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks("\endofdoc").Range)
oPara2.Range.Text = "Heading 2"
oPara2.Format.SpaceAfter = 6
oPara2.Range.InsertParagraphAfter

'Insert another paragraph.
Set oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks("\endofdoc").Range)
oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:"
oPara3.Range.Font.Bold = False
oPara3.Format.SpaceAfter = 24
oPara3.Range.InsertParagraphAfter

'Insert a 3 x 5 table, fill it with data and make the first row
'bold,italic.
Dim r As Integer, c As Integer
Set oTable = oDoc.Tables.Add(oDoc.Bookmarks("\endofdoc").Range, 3, 5)
oTable.Range.ParagraphFormat.SpaceAfter = 6
For r = 1 To 3
For c = 1 To 5
oTable.Cell(r, c).Range.Text = "r" & r & "c" & c
Next
Next
oTable.Rows(1).Range.Font.Bold = True
oTable.Rows(1).Range.Font.Italic = True

'Add some text after the table.
'oTable.Range.InsertParagraphAfter
Set oPara4 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks("\endofdoc").Range)
oPara4.Range.InsertParagraphBefore
oPara4.Range.Text = "And here's another table:"
oPara4.Format.SpaceAfter = 24
oPara4.Range.InsertParagraphAfter

'Insert a 5 x 2 table, fill it with data and change the column widths.
Set oTable = oDoc.Tables.Add(oDoc.Bookmarks("\endofdoc").Range, 5, 2)
oTable.Range.ParagraphFormat.SpaceAfter = 6
For r = 1 To 5
For c = 1 To 2
oTable.Cell(r, c).Range.Text = "r" & r & "c" & c
Next
Next
oTable.Columns(1).Width = oWord.InchesToPoints(2) 'Change width of columns 1 & 2.
oTable.Columns(2).Width = oWord.InchesToPoints(3)

'Keep inserting text. When you get to 7 inches from top of the
'document, insert a hard page break.
Pos = oWord.InchesToPoints(7)
oDoc.Bookmarks("\endofdoc").Range.InsertParagraphAfter
Do
Set oRng = oDoc.Bookmarks("\endofdoc").Range
oRng.ParagraphFormat.SpaceAfter = 6
oRng.InsertAfter "A line of text"
oRng.InsertParagraphAfter
Loop While Pos >= oRng.Information(wdVerticalPositionRelativeToPage)
oRng.Collapse (wdCollapseEnd)
oRng.InsertBreak wdPageBreak
oRng.Collapse wdCollapseEnd
oRng.InsertAfter "We're now on page 2. Here's my chart:"
oRng.InsertParagraphAfter

'Insert a chart and change the chart.
Set oShape = oDoc.Bookmarks("\endofdoc").Range.InlineShapes.AddOLEObject( _
ClassType:="MSGraph.Chart.8", FileName _
:="", LinkToFile:=False, DisplayAsIcon:=False)
Set oChart = oShape.OLEFormat.Object
oChart.charttype = 4 'xlLine = 4
oChart.Application.Update
oChart.Application.Quit
'... If desired, you can proceed from here using the Microsoft Graph
'Object model on the oChart object to make additional changes to the
'chart.
oShape.Width = oWord.InchesToPoints(6.25)
oShape.Height = oWord.InchesToPoints(3.57)

'Add text after the chart.
Set oRng = oDoc.Bookmarks("\endofdoc").Range
oRng.InsertParagraphAfter
oRng.InsertAfter "THE END."

'All done. Unload this form.
Unload Me
***************************************************

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧