Saving invoices as Word Docs


New Member
Aug 19, 2002
Please help!!!! I am creating invoices using Excel and word. I have the Data Stored in an EXCEL Spread Sheet and am merging it with a word document. I have merge Fields named Product, Description, InvoiceNumber, DueDate, CustomerNumber etc. The Merge works fine. I am Also able to save each Invoice as a Seperate Document.
The problem that I need to fix is that each document that is save need to be named as a combination of the "CustomerNumber" Field and The "InvoiceNumber" Field
i.e. Say that CustomerNumber = 205 and the InvoiceNumber= A2698
I want the document to be saved as "A2698205.DOC"
How can I do this??? Any Help is greatly Appreciated.

Attached is the code I am Currently Using

Sub SaveRecsAsFiles()

AllSectionsToSubDoc ActiveDocument
'Save each Subdoc as a separate file
SaveAllSubDocs ActiveDocument
End Sub

Sub AllSectionsToSubDoc(ByRef doc As Word.Document)
Dim secCounter As Long
Dim NrSecs As Long

NrSecs = doc.Sections.Count

For secCounter = NrSecs - 1 To 1 Step -1
doc.Subdocuments.AddFromRange _
Next secCounter

End Sub

Sub SaveAllSubDocs(ByRef doc As Word.Document)
Dim subdoc As Word.Subdocument

Dim newdoc As Word.Document
Dim docCounter As Long

docCounter = 1

doc.ActiveWindow.View = wdMasterView

For Each subdoc In doc.Subdocuments

Set newdoc = subdoc.Open

'Remove NextPage section breaks
'originating from mailmerge
RemoveAllSectionBreaks newdoc

With newdoc
.SaveAs FileName:="c:MergeResult" & CStr(docCounter)
End With
docCounter = docCounter + 1
Next subdoc
End Sub

Sub RemoveAllSectionBreaks(doc As Word.Document)
With doc.Range.Find
.Text = "^b"
With .Replacement
.Text = ""
End With
.Execute Replace:=wdReplaceAll
End With
End Sub

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Jack in the UK

Well-known Member
Feb 16, 2002

letters, invoices or receipt all finance guys stuff, i fell you could have easier life if you copy what i do, trust me its simple once you get the maintance bit solved. I use this all day everyday and the power is awesome.

Its all in one sheet, and save to seperat xls docs, when printed, no one can tell the difference.

are you intrested? if so ill sort a wkbk and email you to try, and we can work from there!

Ill post the code a bit later, its poss you could have any amounts of documents, i have 3 or 7, but im a bit leary like that.

Save as ??? how ever you like, all you desire we can..

Upvote 0


New Member
Aug 19, 2002
Sometimes I have to convert these to RTF and it is much easier for me to convert them from word to RTF then it is to Convert from EXCEL to RTF
Upvote 0


Well-known Member
Jul 27, 2002

Following procedure may get You started and You need to set a reference to the Word-library via Tools | Reference in the VB-editor:

<FONT color=blue>Private <FONT color=blue>Sub </FONT></FONT>ExportInvoice()

<FONT color=blue>Dim </FONT>wdApp<FONT color=blue> As</FONT> Word.Application

<FONT color=blue>Dim </FONT>rnFnr, rnEpost<FONT color=blue> As</FONT> Range

<FONT color=blue>Set </FONT>rnFnr = ThisWorkbook.Worksheets("Fakturamall").Range("F5")

<FONT color=blue>Set </FONT>rnEpost = ThisWorkbook.Worksheets("Fakturamall").Range("L6")

Application.ScreenUpdating =<FONT color=blue> False</FONT>


<FONT color=blue>Set </FONT>wdApp = GetObject("", "Word.Application")


<FONT color=blue>On Error</FONT> <FONT color=blue>GoTo</FONT> 0

<FONT color=blue>With </FONT>wdApp.Selection

.EndKey Unit:=wdStory


.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _

Placement:=wdFloatOverText, DisplayAsIcon:=False

<FONT color=blue>End With</FONT>

wdApp.ChangeFileOpenDirectory ThisWorkbook.Path

<FONT color=blue>With </FONT>wdApp.ActiveDocument

.SaveAs Filename:=CStr(rnFnr.Value) & ".doc"

.Protect Password:="maddogmaddog", NoReset:=False,<FONT color=blue> Type</FONT>:= _



<FONT color=blue>End With</FONT>


<FONT color=blue>Set </FONT>wdApp =<FONT color=blue> Nothing</FONT>

<FONT color=blue>With </FONT>Application

.CutCopyMode =<FONT color=blue> False</FONT>

.ScreenUpdating =<FONT color=blue> True</FONT>

<FONT color=blue>End With</FONT>

<FONT color=blue>End Sub</FONT>


Upvote 0


Well-known Member
Aug 13, 2002
Okay. This is my understanding of what you have now.

You have an Excel procedure that merges your data in Excel into one Microsoft Word Merged document.

You then redefine the merged document as a Master document. The subdocuments of the Master document are the individual "merged" word sections.

Now, when you save the files separately you want to have your specific file naming convention.

Procedurely it might be better to do the following:

Setup the MAIN merge document as you have now. The field codes that you want in the filename should be assigned a style name. Like Name_PartA and Name_PartB.

What I would do differently is that once you have the main merge document take it apart section by section. So you take the first section. Cut it from the merged document. Copy it into a new document (based off of a template that gives you the correct page settings (margins, headers/footers). Do a styleref lookup on Name_PartA and Name_PartB to get the parts of the filename. Then save the file and close.

Go back to the merged document and repeat till there are no more sections.

Upvote 0

Forum statistics

Latest member

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
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 "".
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