?
Solved

VBA ( Writing information to word documents)  !!!!!!!! Please .........................

Posted on 2003-03-20
4
Medium Priority
?
191 Views
Last Modified: 2010-05-01

I want write the some information into word document through VB.
The documents should be saved.I am using word Object Library...
The informations are below

Account_No     700
Recipient_no     708
First_Name     David
Last_Name     Williams
Address1     1000 Lindeena Lane
Address2
City          Urbandale
State          SA
Country
Zip          96012
From_Date     01-17-2003
To_date          02-16-2003

If anyone knows please help me...

Advance thanks.........

Thanks,
caroline
0
Comment
Question by:caroline_us_2003
[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
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
Cimperiali earned 200 total points
ID: 8179614
Play a bit with this code:
Option Explicit
'put a reference to
'Microsoft Word (highest value) object library
Private wdApp As Word.Application

Private Sub Command1_Click()
Dim strToBeWrite As String
Dim wdDoc As Word.Document
Dim wdRange As Word.Range
Dim strFileName As String
'ask for a file name to save to a new doc
strFileName = InputBox("Eneter disk\Path\Name of the doc file", "NewDoc", "c:\myNewDoc.doc")
'prepare text to be written:
'note: vbcrlf= a new line
'chr(9) a tab
strToBeWrite = "Account_No" & Chr(9) & "700"
strToBeWrite = strToBeWrite & vbCrLf & "Recipient_no" & Chr(9) & "708"
strToBeWrite = strToBeWrite & vbCrLf & "First_Name" & Chr(9) & "David"
strToBeWrite = strToBeWrite & vbCrLf & "Last_Name" & Chr(9) & "Williams"
strToBeWrite = strToBeWrite & vbCrLf & "Address1" & Chr(9) & "1000 Lindeena Lane"
strToBeWrite = strToBeWrite & vbCrLf & "Address2"
strToBeWrite = strToBeWrite & vbCrLf & "City" & Chr(9) & "Urbandale"
strToBeWrite = strToBeWrite & vbCrLf & "State" & Chr(9) & "SA"
strToBeWrite = strToBeWrite & vbCrLf & "Country"
strToBeWrite = strToBeWrite & vbCrLf & "Zip" & Chr(9) & "96012"
strToBeWrite = strToBeWrite & vbCrLf & "From_Date" & Chr(9) & "1-17-2003"
strToBeWrite = strToBeWrite & vbCrLf & "To_date" & Chr(9) & "2-16-2003"
'instantiate word
Set wdApp = New Word.Application
   'create a new document
   Set wdDoc = wdApp.Documents.Add
      'add text
      wdDoc.Content = strToBeWrite
      'save the doc
      wdDoc.SaveAs strFileName
      'close the doc
      wdDoc.Close
   'free resources  
   Set wdDoc = Nothing
   'close word
   wdApp.Quit
'free resources
Set wdApp = Nothing
End Sub
0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8179619
Wooopss.. did not see it as about Vba! Sorry...
0
 

Author Comment

by:caroline_us_2003
ID: 8182428
Dear Cimperiali ,

                Thanks lot........
Its working perfectly.....
Thanks for your help...


Thanks,
caroline
0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8182478
;-)
you're welcome
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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

752 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