Solved

Vb to MS word

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

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…
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…
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…

773 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