Sub combined()
Call SetFormRef
Call DataObj
End Sub
Sub SetFormRef()
'Add temporary Userform
Dim Vuf, Uf
Set Uf = ThisWorkbook.VBProject.VBComponents.Add(3)
'Include the UF in the Userforms collection
Set Vuf = VBA.UserForms.Add(Uf.Name)
'remove userform
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=Uf
End Sub
Sub DataObj()
'shows&places selection in C/Test.doc
'syntax for dataobject use
Dim mydata As DataObject
Dim Astring As String
Selection.Copy
Set mydata = New DataObject
mydata.GetFromClipboard
Astring = mydata.GetText(1)
MsgBox Astring
Set mydata = Nothing
Application.CutCopyMode = False
'eg of late binding use
Dim Wapp2 As Object, Test As String
Test = "C:\Test.doc" 'this location has to exist
Set Wapp2 = CreateObject("Word.Application")
On Error GoTo FixErr
Wapp2.documents.Open Filename:=Test, ReadOnly:=False
Wapp2.activedocument.Select
With Wapp2.activedocument
.Range(0, .Characters.Count).Delete
.content.insertafter Astring
End With
Wapp2.activedocument.Close savechanges:=True
Wapp2.Quit
Set Wapp2 = Nothing
Exit Sub
FixErr:
On Error GoTo 0
MsgBox "You need a file: " & Test
Wapp2.Quit
Set Wapp2 = Nothing
End Sub