Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

How to create a word new document(.doc) through VB?. VBA

How to create a  new word document(.doc) through VB?.

if anyone knows please help me.

Advanced  thanks,


Thanks,
Merlin
0
merlin_vb
Asked:
merlin_vb
1 Solution
 
graham_charlesCommented:
   Dim newApp As Object  
    Set newApp = CreateObject("Word.Application")
    newApp.Documents.Add
    newApp.Visible = True

You can also just use

   Dim newApp As Word.Application

...but you'd need to include the Microsoft Word object library in your application.

Now, the only question is... what do you want to do with the new document?

g.
0
 
SteinerCommented:
Some additional thoughts:
If you want to work further with your newly created document, I'd advise to create an object for that document, too.

After including the library like g. said, use the following code example:


Sub UseWord()
   Dim WdApp As Word.Application, WdDoc As Word.Document
   
   Set WdApp = CreateObject("Word.Application")
   WdApp.Visible = True
   
   Set WdDoc = WdApp.Documents.Add  'up to here the same as g.
   With WdDoc
      'Do what you want with the document
      .Range.Text = "That's a new document..."
   End With
   
   
   'Some cleanup, you could close Word via WdApp.Quit if you like, or save the doc
   'WdDoc.Save
   'WdApp.Quit
   Set WdDoc = Nothing
   Set WdApp = Nothing
End Sub
0
 
SiebeCommented:
If you just need to create a new document and no further editing of it, why don't you just put an empty document in your app path and then let it copy to where ever you want to be 'created'.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CleanupPingCommented:
merlin_vb:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
merlin_vb, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
0
 
YensidModCommented:
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now