Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create a word document in VB

Posted on 2003-11-19
8
Medium Priority
?
672 Views
Last Modified: 2010-05-01
How can I create a word document in Word a simple syntax example will suffice. I' m a newbie in VB I have been doing ASP, so it may be similar in asp. Thanks. Also which object library do I use.
0
Comment
Question by:7of9121098
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 9781674
reference ms word object library under project/references:

Dim wdApp as New Word.Application
Dim wdDoc as Word.Document

set wdDoc = wdApp.documents.Add ("<path to new file>")

'' add whatever you want to the doc

wdDoc.save

wdDoc.close
set wdDoc = nothing

wdApp.quit
set wdApp = nothing
0
 

Author Comment

by:7of9121098
ID: 9782601
How do I add whatever you want to the doc, what property?

0
 
LVL 18

Expert Comment

by:bobbit31
ID: 9782656
wdApp.Selection.TypeText "Hello World"
wdApp.Selection.TypeParagraph '' this is a newline/cr

if you want to do bold and the like... i'd suggest recording a new macro. Type stuff, make stuff bold, insert picture, whatever... then go to edit the macro and you can see the code on how to do it.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:7of9121098
ID: 9782861
bobbit31, I get an error when I try to create the new word document. Did I do something wrong?

set wdDoc = wdApp.documents.Add ("c:\temp\newfile.doc")
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 9782905
what's the error?
0
 

Author Comment

by:7of9121098
ID: 9782972
The word document has to exist otherwise I get an error: path invalid...error.
I works fine it the newfile.doc exists in the path, otherwise a error occurs.

How do I make it so I can create a new word document....instead of have a preexisting document in the directory path?
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 200 total points
ID: 9783140
oops, just do:

wdApp.documents.Add
set wdDoc = wdApp.ActiveDocument

then

wdDoc.saveas "C:\temp\newfile.doc"
0
 

Author Comment

by:7of9121098
ID: 9783250
Your the man!, thanks....

  Dim wdApp As New Word.Application
  Dim wdDoc As Word.Document

  wdApp.documents.Add
  wdApp.Selection.TypeText "Hello World"
  wdApp.Selection.TypeParagraph 'new line
  wdApp.Selection.TypeText "Hello World2"
  Set wdDoc = wdApp.ActiveDocument

  wdDoc.saveas "C:\temp\newfile.doc"
  wdDoc.Close
  Set wdDoc = Nothing

  wdApp.quit
  Set wdApp = Nothing
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question