Solved

Vb to MS word

Posted on 2004-09-23
2
179 Views
Last Modified: 2010-05-02
Hi:

My problems is:in a vb application,i want to code when user click to a button it will create a MS word(.doc) file to fill some data(text)and image into this word file.So how to do that?

 At the same time,i wish can adjust some properties  for that word doc in vb coding when that user click to that print button(for example adjust the margin of that word doc.....)


Thanks...
0
Comment
Question by:qfren
[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
2 Comments
 
LVL 4

Accepted Solution

by:
avi247 earned 125 total points
ID: 12139954
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oPara1 As Word.Paragraph
Dim oPara2 As Word.Paragraph
' Application type
Set oWord = New Word.Application
oWord.Visible = True
'objWord.Documents.Open "C:\word.doc"
Set oDoc = oWord.Documents.Add
' set page setup, margins here
With oWord.Selection.PageSetup
    .Orientation = wdOrientPortrait
    .TopMargin = InchesToPoints(1)
    .BottomMargin = InchesToPoints(1.5)
    .LeftMargin = InchesToPoints(1.5)
    .RightMargin = InchesToPoints(1)
    .Gutter = InchesToPoints(0.25)
End With

' add text
Set oPara1 = oDoc.Content.Paragraphs.Add
With oPara1.Range
    .Text = "Experts Exchange"
    .Font.Size = 12
    .Font.Bold = True
    .InsertParagraphAfter
End With

Set oPara2 = oDoc.Content.Paragraphs.Add
oPara2.Range.Text = "Visual Basic"

' add an image
oWord.Selection.InlineShapes.AddPicture "C:\envelope.gif", False, True

oDoc.SaveAs ("C:\expert1.doc")
oDoc.Close
oWord.Quit
Set oPara1 = Nothing
Set oPara2 = Nothing
Set oDoc = Nothing
Set oWord = Nothing
0
 
LVL 8

Author Comment

by:qfren
ID: 12156861
Thanksl for reply...
GIve me sometime to apply it and i will back here...



mc
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

705 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