Consulting

Results 1 to 2 of 2

Thread: Creating an Object which is the same as CreateObject

  1. #1
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location

    Creating an Object which is the same as CreateObject

    I would like to create an object that is identical to

    Private Sub Command0_Click() 
        Dim wApp As Object 
        Dim oRng As Word.Range 
        Dim lngFileNum As Long 
        Dim lngErr As Long 
         
        On Error Resume Next 
        lngFileNum = FreeFile() 
        Open "c:/temp/test.docm" For Input Lock Read As #lngFileNum 
        Close lngFileNum 
        filestatus = Err 
         
        If filestatus = 0 Then 
            Set wApp = CreateObject("Word.Application") 
            wApp.Documents.Open "c:/temp/test.docm" 
            wApp.Visible = True 
            Set oRng = wApp.ActiveDocument.Content 
        Else 
            Set wApp = GetObject(, "Word.Aplication") 
            Set wApp = GetObject("C:/temp/test.docm") 
            Set oRng = wApp.Sections(1).Range 
        End If 
         
        Debug.Print oRng.Text 'Used to verify it works
    End Sub

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You already have this matter under discussion in your other thread: http://www.vbaexpress.com/forum/show...s-already-open
    Kindly don't start threads that duplicate discussions elsewhere. Thread closed.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

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