#1
|
|||
|
|||
Batch create Word documents
I have a list of about 250 topics, each of which I need to create an individually named Word document for. E.g.
Topic - boil an eggDoes anyone know of a way to do this? I thought of using the merge functionality, which would allow me to insert the topic name in <Title> in the template, but the merge functionality does not allow me to specify the file name. Thanks! P.S. This is not a batch conversion task! |
#2
|
||||
|
||||
Hi cdfj,
This could be done with a macro, but you'll need to provide more details about how the list is stored and where the files are to be created (eg the same folder as the list is in). Also, it's a whole lot easier if the list names are the same as the filenames or, at most, the only difference is the 'How to' expression.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks, Paul,
It struck me today that I'd written a bad example. Clearly it is easiest to have a 100% match between the topic name in the list (in Excel) and the file name - so that the file name is <topic name>.docx The topic list and the created files can be in the same directory X:\...\anywhere\ The tricky thing seems to me to link in a .dot template. I've never written a Word macro, so if you can help me here, I will be very grateful! |
#4
|
||||
|
||||
Do you have a particular template, other than Word's 'Normal' template, in mind?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Yes, one that's been made - just a Word document at present, but it can be saved as a .dot. It can have any name, as required. It's not my template, so can admit it's very clunky.
|
#6
|
||||
|
||||
Try the following Excel macro. You'll need to set the source document's filename correctly in the first 'Set wdDoc' line.
As coded, the macro looks for a docx document and saves the output files in that format. If your source document is a 'doc', not 'docx', change that part of the first 'Set wdDoc' line also. And, if you want to save in the 'doc' format, change 'wdFormatXMLDocument' to 'wdFormatDocument'. Code:
Sub Demo() 'Note: A Reference to the Word Object Model is required. Application.ScreenUpdating = False Dim i As Long Dim wdApp As Word.Application Set wdApp = Word.Application wdApp.Visible = False Dim wdDoc As Word.Document 'Open the source document Set wdDoc = wdApp.Documents.Open(Filename:="C:\Users\" & Environ("UserName") & "\Documents\MyFile.docx", _ AddToRecentFiles:=False, Visible:=False) With ActiveSheet For i = 2 To .Cells.SpecialCells(xlCellTypeLastCell).Row Application.StatusBar = "Creating document " & i 'Save a copy of the document with the new filename wdDoc.SaveAs2 Filename:=.Cells(i, 1).Value, FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False Next End With 'Close the document wdDoc.Close SaveChanges:=False 'Close Word wdApp.Quit Set wdDoc = Nothing: Set wdApp = Nothing Application.StatusBar = "Done!!" Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
That's brilliant and very generous - thank you very much!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Dynamically create documents | MrRikkie | Word VBA | 1 | 10-12-2012 09:15 AM |
Linking Documents via Hyperlinks to create a "packet" | moose288 | Word | 3 | 09-22-2012 08:22 PM |
Batch Edit Links | tosti | PowerPoint | 5 | 01-31-2012 12:51 PM |
Batch run "inspect documents" | ghumdinger | Word VBA | 3 | 07-21-2011 04:53 PM |
Word 2007...Batch Conversion Wizard ??? | mw4man | Word | 0 | 12-18-2008 04:38 PM |