Jysquare
02-15-2012, 06:59 AM
Hello everyone,
First of all I'm a beginner in VBA so please be kind. Let me explain the situation.
I did a mailmerge to create dynamic word pages with customer informations.
Then I did (by looking on the net) a macro to split the result file in several others, each page being saved as one file.
Now I'm looking to give those files some names containing customer info. I googled that and I think the (only?) way is to create a mergefield with that info, at the very beginning of the page, then extract and delete it from the page with a macro to put it in file names.
Exemple : if I have a customer named Vbaexpress I would like to have a file named Facture_Vbaexpress.doc for it.
But I'm totally stuck on how to do that. I found nowhere how to select, extract and then delete this first word from my page.
Any help would be most welcome, here is my "splitting macro", which currently names the files just with an incremented ID :
Sub DecouperDocument()
Application.Browser.Target = wdBrowsePage
For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
ActiveDocument.Bookmarks("\page").Range.Copy
Documents.Add
Selection.Paste
Selection.TypeBackspace
ChangeFileOpenDirectory "C:\test\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="Facture_" & DocNum & ".doc"
ActiveDocument.Close
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
Thanks in advance. By the way I'm using Office 2007.
js
First of all I'm a beginner in VBA so please be kind. Let me explain the situation.
I did a mailmerge to create dynamic word pages with customer informations.
Then I did (by looking on the net) a macro to split the result file in several others, each page being saved as one file.
Now I'm looking to give those files some names containing customer info. I googled that and I think the (only?) way is to create a mergefield with that info, at the very beginning of the page, then extract and delete it from the page with a macro to put it in file names.
Exemple : if I have a customer named Vbaexpress I would like to have a file named Facture_Vbaexpress.doc for it.
But I'm totally stuck on how to do that. I found nowhere how to select, extract and then delete this first word from my page.
Any help would be most welcome, here is my "splitting macro", which currently names the files just with an incremented ID :
Sub DecouperDocument()
Application.Browser.Target = wdBrowsePage
For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
ActiveDocument.Bookmarks("\page").Range.Copy
Documents.Add
Selection.Paste
Selection.TypeBackspace
ChangeFileOpenDirectory "C:\test\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="Facture_" & DocNum & ".doc"
ActiveDocument.Close
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
Thanks in advance. By the way I'm using Office 2007.
js