|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
mail merge error
Hi,
I am trying to merge the word mail merge with VB6. Sudenly its giving me error in the opendataSource method. That is its saying that "OpenDataSource property or method is not available because preview mode is active" Here is my code Dim app As Word.Application Dim doc As Word.Document app = CreateObject("Word.Application") doc = app.Documents.Add app.PrintPreview = False With doc.MailMerge With .Fields .Add(app.Selection.Range, "Contact_Name") app.Selection.TypeParagraph() .Add(app.Selection.Range, "Address") End With Dim autotxt As Word.AutoTextEntry autotxt = app.NormalTemplate.AutoTextEntries.Add("MyLabelLayout", doc.Content) doc.Content.Delete() .MainDocumentType = Word.WdMailMergeMainDocType.wdMailingLabels .OpenDataSource(Name:="C:\data.txt") app.MailingLabel.CreateNewDocument(Name:="5160", Address:="", AutoText:="MyLabelLayout") .Destination = Word.WdMailMergeDestination.wdSendToNewDocument .Execute() autotxt.Delete() Anybody knows anything about this error? If you know please help me. Regards Rechen |
|
#2
|
|||
|
|||
|
Hi,
You've already found the solution with the following instruction : app.PrintPreview = False therefore it's ok with a the correct format for your data.txt source. For example, for its content you can choose ; as separator like this : Contact_Name;Address Emmanuel;10 code street vb city Here's your vb code customized to see what happens : Dim app As Word.Application Dim doc As Word.Document Set app = CreateObject("Word.Application") app.Visible = True Set doc = app.Documents.Add app.PrintPreview = False With doc.MailMerge With .Fields .Add app.selection.Range, "Contact_Name" app.selection.TypeParagraph .Add app.selection.Range, "Address" End With Dim autotxt As Word.AutoTextEntry Set autotxt = app.NormalTemplate.AutoTextEntries.Add("MyLabelLayout", doc.content) doc.content.Delete .MainDocumentType = Word.WdMailMergeMainDocType.wdMailingLabels .OpenDataSource Name:="C:\Data.txt" app.MailingLabel.CreateNewDocument Name:="5160", Address:="", AutoText:="MyLabelLayout" .Destination = Word.WdMailMergeDestination.wdSendToNewDocument .Execute End With autotxt.Delete app.Quit |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > mail merge error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|