Solved

Vb to MS word

Posted on 2004-09-23
2
158 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
Comment Utility
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
Comment Utility
Thanksl for reply...
GIve me sometime to apply it and i will back here...



mc
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now