Click to See Complete Forum and Search --> : Create a .doc file in VBA Excel
Helder Barros
Oct 29th, 2005, 01:24 PM
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
RobDog888
Oct 29th, 2005, 01:33 PM
Yes, in Excel VBA IDE you just need to add a reference to MS Word xx.0 Object Library. And then code like below.
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.