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
Solved

Vb to MS word

Posted on 2004-09-23
2
169 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

861 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