Saving invoices as Word Docs

manrav

New Member
Joined
Aug 19, 2002
Messages
14
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 _
doc.Sections(secCounter).Range
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)
.Close
End With
docCounter = docCounter + 1
Next subdoc
End Sub

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

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
hi

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

Jack
 
Upvote 0
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
manrav,

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

<PRE>
<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>



ThisWorkbook.Sheets("Fakturamall").Range("Faktura").Copy



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



wdApp.Documents.Add



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

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

.EndKey Unit:=wdStory

.TypeParagraph

.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>:= _

wdAllowOnlyComments

.Close

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



wdApp.Quit

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


</PRE>

HTH,
Dennis
 
Upvote 0
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.

g-
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

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