0

I have an Excel file that looks like this:

     A          B
1  Title_1  Description_1
2  Title_2  Description_2

Is it possible to output each title and description to individual Word files with column A for file name of the Word file and column B to its content?

For example the macro would create a new Word file give it file name 'Title_1' and copy 'Description_1'. Then create a new Word file again give it file name 'Title_2' and copy 'Description_2'. And do this until all data from the Excel file is copied.

Thank you for your time. :)

Leoxanigm
  • 27
  • 1
  • 1
  • 8
  • 1
    Have you tried anything so far? If you show that you've tried solving this yourself, you'll get a good response from the geniuses on this site! – LondonRob Jul 07 '15 at 23:00

3 Answers3

0

What you want to look into is called a "Mail Merge". Use a search engine and look for "mail merge excel word 2007" (or whatever year of MS Office that you are working with). You can create an excel macro that creates instances of word, populates the word doc with whatever you want from your excel spreadsheet, save the word doc with any name you want, export to PDF, etc.

n8.
  • 1,732
  • 3
  • 16
  • 38
0

Here are some hints to start you off:

in the VBE go to tools references and add one for Microsoft Office.

Use these two lines of code to create an object:

Dim MyWord
Set MyWord = CreateObject("Word.Application")

Now you can precede any code for word with MyWord for example to add a Document in word would be Documents.Add so remotely from Excel it will be MyWord.Documents.Add

You will want to loop through your cells in excel. On each iteration of the loop populate two variables, one with the text you want in the file and one with the file name.

Then simply use MyWord to enter the results of the variable then save the file using the result of the other variable.

Post back if you get stuck but give it a go first.

Dan Donoghue
  • 6,056
  • 2
  • 18
  • 36
-2

This is easy form any operating system, assuming you are using windows you will use a batch script(easiest).

First use save as/export on the data ribbon to save as a CSV.

Second you will need a batch script to read the CSV and use the first value as the file name the second value as the contents. If you want it to be a doc or docx instead of txt just rename the file in the same loop or add it to the file name when you output to text.

Here is a similar post with all the resources you would need to slap together a quick batch script.

read csv file through windows batch file and create txt file

Community
  • 1
  • 1
Travis
  • 25
  • 1
  • 7
  • The OP states they're looking for a macro (i.e. VBA) solution. – LondonRob Jul 07 '15 at 23:02
  • A renamed text file is not a word document, as much as word will open it it is just a text file. For example, create a text file with some basic text in it, open it in word and save it as a word doc (docx). Now rename both files to .zip extension, open them both and see what happens. – Dan Donoghue Jul 07 '15 at 23:23
  • I see he listed it as VBA but he didn't really specify what his goal was or that it had to be a VBA macro. Also your talking about semantics, yes a text file is not a zip file... but if you are simply attempting to get text into a format that will open with word(ie. what his post indicated) my solution would work exactly for that purpose. – Travis Jul 09 '15 at 05:53