Home > Software engineering >  GetObject make a day did not understand, jumpy
GetObject make a day did not understand, jumpy

Time:10-27


The code in VB6, a timer, timer below
Dim OBJ As Object

On the Error Resume Next

The Set OBJ=GetObject (, "excel. Application")

The debug. Print err. The Description


Very strange question

If the program is run before, has opened the EXCEL,, then the display is OK (theory) also

If the program is running, then open the EXCEL, or display the running error (ACTIVEX cannot create, etc.)

But, how to EXCEL program lost focus, just click on the other forms, then shows the normal again,,, don't understand why

Is now a program is running, then open the EXCEL, after open the EXCEL, if you don't have no lose EXCEL activated state, so has been an error, and according to the theory, EXCEL at this time already open, the GetObject should be captured by EXCEL,, why or display an error, but the strange thing is, open the EXCEL to check it after other forms can normal again,,

Don't understand, and has set up a day, and didn't understand

CodePudding user response:

Getobject for already open file object, must specify the file name the full path (first parameter), if there is no use filename parameter, effect is the same as the createobject

CodePudding user response:

Thank you for your answer, but I still don't understand

May I show before is not good, I again

The program only in the timer has the following code

Dim OBJ As Object
On the Error Resume Next
The Set OBJ=GetObject (, "excel. Application")
The debug. Print err. The Description


1. When the execution procedures, if the execution of the program before they have opened the EXCEL, so err. The Description is empty, that is no error values
2. If the process is executed (EXCEL) is not running, so err. The Description is the Description of the ActiveX components can't create objects

Have good understanding, 1, 2, the problem is that the following

3.
A. the executor (haven't open the EXCEL) error message for ActiveX components can't create the object

B. Double-click the desktop EXCEL, open the EXCEL program error message or ActiveX components can't create objects (why, has opened the EXCEL at this time, should be GetObject won't return an error again!) - problem point

C. opened the EXCEL, EXCEL program is activated, literally one click other forms (to EXCEL program is not active), the program no longer appear error messages, this point don't understand, why, when the EXCEL lost focus is good -- -- -- -- -- why


Above is only four lines of code, please try (VB 6 + OFFICE 2003 + 7 or WINXP)

It should be said that, if not EXCEL, but other software, such as jinshan WPS, so the above code is the same wording, won't appear this kind of problem,,



CodePudding user response:

Is the problem when writing rots,
Excel like write when loses focus, WPS like writing at startup, the timing is a developer's personal preferences, there is no hard and fast rules,
  • Related