Macro to create and save a word document with text

diogene

New Member
Joined
Jun 20, 2018
Messages
4
Hi everyone,

I would need some help: I have an excel spreadsheet which, based on the name of my potential customers, automatically creates the text to insert in the letter I will send them. To further automatise the process, I would like to have a macro that takes the text in the second cell of column E (the text of my letter), creates a new word document, paste the text in it and saves the word document in a specified folder (possibly named as cell B2 + cell C2, with a space in the middle).

Is there anyone who can help me with this?

It would really be a life saver!

Many thanks :)
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Not really, actually. I am not looking to modify the text of the email but just to create a word document containing the text from Excel, which will be later sent as an attachment (no need for that to be automated, I can send it, I just need the word docs to be created and saved in a folder).
 
Upvote 0
Your first post makes no mention of an email. You need to be clearer about what you're trying to achieve.
 
Upvote 0
Hi diogene
Does not do exactly what you asked for but its not difficult to change so that text, adresses etc are grabbed from a sheet instead of the simple lines in my example below.

Code:
Public Sub MailIT()
Dim applOL As Outlook.Application
Dim miOL As Outlook.MailItem
Dim wApp As Word.Application
Dim wDoc As Word.Document

    ' Lets create a doc with some simple content
    '
    Set wApp = CreateObject("Word.Application")
    wApp.Visible = True
    Set wDoc = wApp.Documents.Add
    wDoc.Content.InsertAfter "TEST TEXT IN WORD DOC"
    wDoc.SaveAs ("H:\MyNewWordDoc.doc")
    wDoc.Close
    wApp.Quit
    Set wDoc = Nothing
    Set wApp = Nothing


    ' Lets create an email, add attachement
    '
    Set applOL = New Outlook.Application
    Set miOL = applOL.CreateItem(olMailItem)

    With miOL
        .To = "target@targetsadress.se"
        .CC = ""
        .Subject = "TESTSUBJECT"
        .Body = "TEST BODY TEXT"
        .Attachments.Add "H:\MyNewWordDoc.doc"
        .Display
        '.Send
    End With
  
    Set applOL = Nothing
    Set miOL = Nothing
End Sub

Good luck :)
 
Upvote 0

Forum statistics

Threads
1,213,568
Messages
6,114,348
Members
448,570
Latest member
rik81h

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top