Home > Software engineering >  VB operation WORD of a very simple code, debugging is not wrong, after the generated EXE to real-tim
VB operation WORD of a very simple code, debugging is not wrong, after the generated EXE to real-tim

Time:10-02

Dim MyWord As Word. Application
The Set MyWord=CreateObject (" Word. Application ")
MyWord. Visible=False
End Sub
Debug state run successfully, but after generated EXE error:
The Run - time error "- 2147352577 (8001 FFFF)
Automation error the An internal error occurred
Already do a good job in a few days not fix, please experienced people to help me, thank you,

CodePudding user response:

Usually permissions or antivirus software problems,
With administrator privileges to run, and close the anti-virus software,

CodePudding user response:

You test with a simple code (I have a ready-made excel code), if everything is ok, that is a question of your code, if not through, is probably the permissions problems such as:
 Dim MyExcel As Excel. Application 
The Set MyExcel=CreateObject (" Excel. Application ")
MyExcel. Visible=False
Dim mBook As Excel Workbook, Sht As Excel. The Worksheet
The Set mBook=MyExcel. Workbooks. Add
The Set of Sht=mBook. Worksheets. Add
Sht. Range (" a1 "). The Value="HTTP://https://bbs.csdn.net/topics/this is the test code... "
MBook. SaveAs "d: \ test. XLS"
MBook. Close True
The Set of Sht=Nothing
The Set mBook=Nothing
MyExcel. Quit
The Set MyExcel=Nothing



Create a new project, reference microsft excel 11.0...
Copy the code compiled into an exe file and then test the exe file

CodePudding user response:

Your code is excel, excel is no problem, I've tried, but the WORD is, my program I wrote that few lines, there is no other code, generated EXE error, debugging is not wrong,

CodePudding user response:

Oh, then get a word:
 Sub Test () 
Dim MyWord As Word. Application. Doc As Word Document
The Set MyWord=New Word. Application
MyWord. Visible=False
The Set of Doc=MyWord. Documents. The Add
Doc. ActiveWindow. Selection. TypeText Text:="this is a test of a boring... "
Doc. SaveAs "d: \ test. Doc"
Doc. Close
The Set of Doc=Nothing
MyWord. Quit
The Set MyWord=Nothing
End Sub



.

CodePudding user response:

Dim MyWord As Word. Application
Instead of
Dim MyWord As Object
Try again,

CodePudding user response:

The Set MyWord=New Word. Application
Dim MyWord As Object
Can't,,,,

CodePudding user response:

Dim MyWord As Word. Application. Doc As Word Document
The Set MyWord=New Word. Application

===& gt;
Dim MyWord As Object, Doc As Object


On the error resume next
The Set MyWord=CreateObject (" Word. Application ")
If err<> 0 then
The Set MyWord=GetObject (" Word. Application ")
End the if

So have a try, I haven't wrote a bit rusty, called word \ for as far as possible don't use explicitly declared, CreateObject another already exists in the external program memory may produce a runtime error

CodePudding user response:

Dim MyWord As Word Application 'this is what mean?
The Set MyWord=CreateObject (" Word. Application ") 'this is what meaning, zha feel so repeat? Can't get rid of the first sentence?
MyWord. Visible=False
End Sub

CodePudding user response:

Instead of
The Set MyWord=CreateObject (" Word. Application ")
MyWord. Visible=False
End Sub
Generated EXE, after test no problem, I here (the machine is equipped with VB, WORD2003)
  •  Tags:  
  • VBA
  • Related