A
Andy
I am trying to write some data and copy some cells from Excel to Word from
Excel.
In Excel VBA, I am trying to open a new Word application and then begin to
write the data.
I seem to be falling at an early fence with this code :-
Dim objWord As Word.Application
Dim WSD As Worksheet
Dim objDoc As Word.Document
Dim wdRn As Word.Range
Dim PreMess as string
Set WSD = ActiveSheet
Set objWord = New Word.Application
Set objDoc = objWord.NewDocument
PreMess = "Hello"
Set wdRn = objDoc.Range(0, 0)
With wdRn
.InsertParagraph
.InsertBefore PreMess
End With
etc.
The code fails at the line of code - Set objDoc = objWord.NewDocument
The error is 'Type mismatch' - error 13
So I am successfully creating the application but not a new document within
the application.
I guess you can see what I am trying to do - can anyone help?
At some point I will also need to save the document and close the Word
application but struggling to find this using F2.
Thanks.
Excel.
In Excel VBA, I am trying to open a new Word application and then begin to
write the data.
I seem to be falling at an early fence with this code :-
Dim objWord As Word.Application
Dim WSD As Worksheet
Dim objDoc As Word.Document
Dim wdRn As Word.Range
Dim PreMess as string
Set WSD = ActiveSheet
Set objWord = New Word.Application
Set objDoc = objWord.NewDocument
PreMess = "Hello"
Set wdRn = objDoc.Range(0, 0)
With wdRn
.InsertParagraph
.InsertBefore PreMess
End With
etc.
The code fails at the line of code - Set objDoc = objWord.NewDocument
The error is 'Type mismatch' - error 13
So I am successfully creating the application but not a new document within
the application.
I guess you can see what I am trying to do - can anyone help?
At some point I will also need to save the document and close the Word
application but struggling to find this using F2.
Thanks.