O
Ognjen
Hi
I have to write some text into Word, by VB, end I got an error: ""ActiveX
component can't create object", and in run-time, my program stops working! I
have find, in MSDN, am example about using excel as object type, but there
are some constants, perhaps only for excel? Can I wind, and where, these
const for word, or how can I, without an error, link word an VB? Can anyone
send me an example?
Sub GetExcel()
Dim MyXL As Object ' Variable to hold reference
' to Microsoft Excel.
Dim ExcelWasNotRunning As Boolean ' Flag for final release.
' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
Set MyXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ExcelWasNotRunning = True
There is an error when I change everything into word object!!!
Err.Clear ' Clear Err object in case error occurred.
DetectExcel
Set MyXL = GetObject("c:\vb4\MYTEST.XLS")
.....
Sub DetectExcel()
' Procedure dectects a running Excel and registers it.
Const WM_USER = 1024 '????
Dim hWnd As Long
' If Excel is running this API call returns its handle.
hWnd = FindWindow("XLMAIN", 0)
If hWnd = 0 Then ' 0 means Excel not running.
Exit Sub
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hWnd, WM_USER + 18, 0, 0
End If
End Sub
I have to write some text into Word, by VB, end I got an error: ""ActiveX
component can't create object", and in run-time, my program stops working! I
have find, in MSDN, am example about using excel as object type, but there
are some constants, perhaps only for excel? Can I wind, and where, these
const for word, or how can I, without an error, link word an VB? Can anyone
send me an example?
Sub GetExcel()
Dim MyXL As Object ' Variable to hold reference
' to Microsoft Excel.
Dim ExcelWasNotRunning As Boolean ' Flag for final release.
' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
Set MyXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ExcelWasNotRunning = True
There is an error when I change everything into word object!!!
Err.Clear ' Clear Err object in case error occurred.
DetectExcel
Set MyXL = GetObject("c:\vb4\MYTEST.XLS")
.....
Sub DetectExcel()
' Procedure dectects a running Excel and registers it.
Const WM_USER = 1024 '????
Dim hWnd As Long
' If Excel is running this API call returns its handle.
hWnd = FindWindow("XLMAIN", 0)
If hWnd = 0 Then ' 0 means Excel not running.
Exit Sub
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hWnd, WM_USER + 18, 0, 0
End If
End Sub