How can I create a .doc file and writing thing in that document using VBA in Excel?
Any one have some exaple to do it?
Thanks in advance,
Hélder Barros
Printable View
How can I create a .doc file and writing thing in that document using VBA in Excel?
Any one have some exaple to do it?
Thanks in advance,
Hélder Barros
Yes, in Excel VBA IDE you just need to add a reference to MS Word xx.0 Object Library. And then code like below.
VB Code:
Option explicit 'Add a reference to MS Word xx.0 object library Private Sub CommandButton1_Click() Dim oApp as word.application dim oDoc as word.document set oapp = new word.application set odoc = oapp.documents.add 'Adds a new blank doc odoc.activate odoc.select selection.TypeText Text:="Hello from Excel VBA" odoc.save odoc.close set odoc = nothing oapp.quit set oapp = nothing End sub