PDA

Click to See Complete Forum and Search --> : Reg Getobject Funtion


shoba
Oct 31st, 2002, 05:20 AM
Hi,
Would anyone please tell me why iam not able to view the word document which already exists.I only get the word application opened but not the actual document.

I gave the following code

dim x as object
set x=getobject("c:\l5.doc")
x.application.visible=true

Expecting your reply,

Thankyou,

shoba

alex_read
Nov 1st, 2002, 03:13 AM
You could always use the creatobject option for this:
Dim objWordApp As Object
Set objWordApp = CreateObject("Word.application")

objWordApp.Visible = True
objWordApp.documents.open "C:\file.doc"

alex_read
Nov 1st, 2002, 03:17 AM
Alternatively, if you're writing this in vb & not from a script try not to use late binding (createobject or getobject functions) and try to use one of these instead:
' At the top of a form
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 Const SW_SHOWNORMAL = 1

Private Sub Form_Load()
ShellExecute Me.hwnd, vbNullString, "C:\Path\file.doc", _
vbNullString, "C:\", SW_SHOWNORMAL
End Sub

or...

'Add a reference to the "Microsoft Word x.0 object library" from the
'the project menu>references option in vb.
Private Sub Form_Load()
Dim wrdApp As Word.Application
Set wrdApp = New Word.Application

wrdApp.Visible = True
wrdApp.Documents.Open "C:\path\file.doc"
End Sub