PDA

View Full Version : Input specific data into word



fadib
10-30-2007, 08:11 PM
Hi guys,
I am trying to generate a VBA code in excel that will do the following:
1-Ask the user to input a in a message box.
2-The number will be stored in A1.
3-With a click of a button, open a new word document.
4-Take the value in A1 and paste it in the word document.
5-Save as the word document on the desktop.

I have read and read, but the only thing I was able to find is to copy and paste special into word document. :(

Can you help me out?

Bob Phillips
10-31-2007, 01:51 AM
Dim oWord As Object
Dim oDoc As Object
Dim ans

ans = InputBox("Supply a value")
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oDoc = oWord.documents.Add
Range("A1").Value = ans
Range("A1").Copy
With oWord.Selection
.TypeParagraph
.Paste
End With

fadib
10-31-2007, 08:17 AM
Thank you so much, that is awesome. :thumb