Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email forms to word document

Status
Not open for further replies.

fezzer

Technical User
Mar 20, 2002
14
GB
Hi! I'm just starting out in programming and it's all looking a bit complicated! I've managed to write a piece of code to process a form for a yearbook i'm compiling so each person will effectively send me a message with answers to all the different questions. Unfortunately Outlook recieves this as a list of "topic=answer" lines. Is there a way of processing these emails so the list of topic answers can be exported directly to Word (and possibly formatted) as otherwise a significant quantity of cutting and pasting will have to take place!

Thanks in advance
 
you could try from your form, creating the word document there,

this code wont work but it would be something along the lines of

first set up a reference to the word object then start your code

Sub SndMail
Dim MyWord as Word.application
Dim Mydoc as document

set myword = createobject("word.application")
set mydoc = myword.newdocument

'this will create a new word document

with mydoc

.TypeText Text:="gratuitis Plug " & me.optionbox1.value

this will insert the worsd and the value of the option button from yuor form

end with

then save the document in the temp drive , the code owuld eb something like

FilNm = "C:\temp\da" & "oc".doc



mydoc.saveas FileName:=FilNm


end sub

if you passed the value of filnm to another funciton or sub you coudl create your e-mail and attach the word docuemtn.

basicly do a search on office automation word and excel on the web to get the exact code to do this, even search through the archives on tek-tips

hope this helps

Chance
 
heres some code that will work


Sub CreateNewWordDoc()
' to test this code, paste it into an Excel module
' add a reference to the Word-library
' create a new folder named C:\Foldername or edit the filnames in the code
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add ' create a new document
' or
'Set wrdDoc = wrdApp.Documents.Open("C:\Foldername\Filename.doc") ' open an existing document
' example word operations
With wrdDoc
For i = 1 To 100
.Content.InsertAfter "Here is a example test line #" & i
.Content.InsertParagraphAfter
Next i
If Dir(&quot;C:\Foldername\MyNewWordDoc.doc&quot;) <> &quot;&quot; Then
Kill &quot;C:\Foldername\MyNewWordDoc.doc&quot;
End If
.SaveAs (&quot;C:\Foldername\MyNewWordDoc.doc&quot;)
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top