PDA

View Full Version : Creating an Object which is the same as CreateObject



heedaf
08-17-2017, 01:37 PM
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

macropod
08-17-2017, 02:04 PM
You already have this matter under discussion in your other thread: http://www.vbaexpress.com/forum/showthread.php?60415-Referencing-a-Word-document-that-is-already-open
Kindly don't start threads that duplicate discussions elsewhere. Thread closed.