?
Solved

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

Posted on 2003-03-20
4
Medium Priority
?
193 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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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

621 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