Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
How to use macro with 2 different template for transition mail mer
Problem : I need to use a macro that work with two different template because of a mail merge. Hello, Ive my macro in offer_crm.dot. It works this way: a) If the document has not been saved it save the doc with protocol name. b) If the document has been saved, it rename the document and save the doc and it refresh the protocol version When i print from CRM the offer for a customer and I use the offer_crm.dot template. With my macro i save the document with its protocol number. But the problem is when I reopen the offer, it ask me for the option of mail merge. At this point then: 1) Print from CRM offert with template offer_crm.dot 2) I do mail merge, and it create a new document from template normal.dot I want to create a macro that make: 1) From my offer with template offer_crm.dot it does a mail merge 2) Now there is a new offert with template normal.dot and it save the document The problem is I want to have one only macro that make all this for me. But when I do mail merge, the macro stop itself and it say its not there anymore. At this point: .Destination = wdSendToNewDocument Is there any way to have only one macro that works in two different template? My code is: Sub CRM() Const conPercorso As String = "c:\offerte" Dim rTMp As Range Dim vTMp As Range Dim protNewVersion As String Dim strNameFile As String Dim strControllo As String Dim prot As String strNameFile = ActiveDocument.Name strControllo = Mid(strNameFile, 1, 5) If strControllo = "Docum" Then With ActiveDocument.MailMerge ..Destination = wdSendToNewDocument ..SuppressBlankLines = True With .DataSource ..FirstRecord = wdDefaultFirstRecord ..LastRecord = wdDefaultLastRecord End With ..Execute Pause:=False End With With ActiveWindow.View ..ShowRevisionsAndComments = False ..RevisionsView = wdRevisionsViewFinal End With ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle CommandBars("Task Pane").Visible = False Set rTMp = Selection.Paragraphs(1).Range If rTMp.Characters(1) = "x" Then rTMp.Start = rTMp.Start + 1 rTMp.End = rTMp.End - 1 rTMp.Select MsgBox rTMp prot = rTMp ChangeFileOpenDirectory conPercorso ActiveDocument.SaveAs FileName:=prot Else MsgBox "Non c'è il numero di protocollo e non è stato salvato il documento" End If Else With ActiveWindow.View ..ShowRevisionsAndComments = False ..RevisionsView = wdRevisionsViewFinal End With protNewVersion = Mid(strNameFile, 1, 17) ChangeFileOpenDirectory conPercorso ActiveDocument.SaveAs FileName:=protNewVersion With Selection ..HomeKey Unit:=wdStory ..MoveDown Unit:=wdLine, Count:=1 ..MoveRight Unit:=wdCharacter, Count:=11 ..MoveRight Unit:=wdCharacter, Count:=17, Extend:=wdExtend ..TypeText protNewVersion End With MsgBox "Il file è stato salvato con il nome del protocollo e il nr. di protocollo è stato aggiornato" End If End Sub Thanks a lot for any suggestions, Best Regards, Samantha |
#2
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
How to use macro with 2 different template for transition mail mer
Hi Samantha,
I'm not certain I'm understanding exactly what you have, and what you need. But it might help if you first could tell us the version of Word involved? Problem : I need to use a macro that work with two different template because of a mail merge. Hello, Ive my macro in offer_crm.dot. It works this way: a) If the document has not been saved it save the doc with protocol name. b) If the document has been saved, it rename the document and save the doc and it refresh the protocol version When i print from CRM the offer for a customer and I use the offer_crm.dot template. With my macro i save the document with its protocol number. But the problem is when I reopen the offer, it ask me for the option of mail merge. At this point then: 1) Print from CRM offert with template offer_crm.dot 2) I do mail merge, and it create a new document from template normal.dot I want to create a macro that make: 1) From my offer with template offer_crm.dot it does a mail merge 2) Now there is a new offert with template normal.dot and it save the document The problem is I want to have one only macro that make all this for me. But when I do mail merge, the macro stop itself and it say its not there anymore. At this point: .Destination = wdSendToNewDocument Is there any way to have only one macro that works in two different template? My code is: Sub CRM() Const conPercorso As String = "c:\offerte" Dim rTMp As Range Dim vTMp As Range Dim protNewVersion As String Dim strNameFile As String Dim strControllo As String Dim prot As String strNameFile = ActiveDocument.Name strControllo = Mid(strNameFile, 1, 5) If strControllo = "Docum" Then With ActiveDocument.MailMerge ..Destination = wdSendToNewDocument ..SuppressBlankLines = True With .DataSource ..FirstRecord = wdDefaultFirstRecord ..LastRecord = wdDefaultLastRecord End With ..Execute Pause:=False End With With ActiveWindow.View ..ShowRevisionsAndComments = False ..RevisionsView = wdRevisionsViewFinal End With ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle CommandBars("Task Pane").Visible = False Set rTMp = Selection.Paragraphs(1).Range If rTMp.Characters(1) = "x" Then rTMp.Start = rTMp.Start + 1 rTMp.End = rTMp.End - 1 rTMp.Select MsgBox rTMp prot = rTMp ChangeFileOpenDirectory conPercorso ActiveDocument.SaveAs FileName:=prot Else MsgBox "Non c'è il numero di protocollo e non è stato salvato il documento" End If Else With ActiveWindow.View ..ShowRevisionsAndComments = False ..RevisionsView = wdRevisionsViewFinal End With protNewVersion = Mid(strNameFile, 1, 17) ChangeFileOpenDirectory conPercorso ActiveDocument.SaveAs FileName:=protNewVersion With Selection ..HomeKey Unit:=wdStory ..MoveDown Unit:=wdLine, Count:=1 ..MoveRight Unit:=wdCharacter, Count:=11 ..MoveRight Unit:=wdCharacter, Count:=17, Extend:=wdExtend ..TypeText protNewVersion End With MsgBox "Il file è stato salvato con il nome del protocollo e il nr. di protocollo è stato aggiornato" End If End Sub Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005) http://www.word.mvps.org This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-) |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Mail merge in Word from Outlook Catagories | Mailmerge | |||
How do you use a template? | Microsoft Word Help | |||
FilePrint macro didn't work after all... | Microsoft Word Help | |||
Modifying a macro in a global template | New Users | |||
Moving templates to other computer | Microsoft Word Help |