Results 1 to 3 of 3

Thread: Reg Getobject Funtion

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    16

    Reg Getobject Funtion

    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

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    You could always use the creatobject option for this:
    VB Code:
    1. Dim objWordApp As Object
    2. Set objWordApp = CreateObject("Word.application")
    3.  
    4. objWordApp.Visible = True
    5. objWordApp.documents.open "C:\file.doc"

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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:
    VB Code:
    1. ' At the top of a form
    2. Private Declare Function ShellExecute Lib "shell32.dll" _
    3. Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
    4. ByVal lpFile As String, ByVal lpParameters As String, _
    5. ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    6.  
    7. Private Const SW_SHOWNORMAL = 1
    8.  
    9. Private Sub Form_Load()
    10.     ShellExecute Me.hwnd, vbNullString, "C:\Path\file.doc", _
    11.     vbNullString, "C:\", SW_SHOWNORMAL
    12. End Sub

    or...

    VB Code:
    1. 'Add a reference to the "Microsoft Word x.0 object library" from the
    2. 'the project menu>references option in vb.
    3. Private Sub Form_Load()
    4.     Dim wrdApp As Word.Application
    5.     Set wrdApp = New Word.Application
    6.    
    7.     wrdApp.Visible = True
    8.     wrdApp.Documents.Open "C:\path\file.doc"
    9. End Sub
    Last edited by alex_read; Nov 1st, 2002 at 04:22 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width