Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ksg ksg is offline
external usenet poster
 
Posts: 13
Default Automated Mail Merge Displaying unwanted Dialog Boxes

I am writing an application that will accept pipe "|" delimited text files
from other applications to be mail merged when receive. I can pick the files
up from the directory, open the main mail document and open the data source;
however when the opendatasource command is executed a dialog box pops up
asking "Text File Connection Properties". I need to pass all the information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio - Visual Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal formfilename As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile



  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Automated Mail Merge Displaying unwanted Dialog Boxes

Word can use at least three different methods to open a plain text file for
use as a data source:
a. its internal text converter. This will pop up a dialog if it doesn't
recognise the field delimiters. There's no way to specify the delimiters in
the OpenDataSource call
b. an OLEDB text provider. This will also typically throw up a prompt
(probably twice, for some reason) for the field delimiter. Again, there is
no way to specify the delimiter in the OpenDataSource call or, as far as I
know, in the OLEDB connection string.
c. an ODBC text driver. In this case, you can specify some of the
characteristics of the file in a SCHEMA.INI file that the driver expects to
find in the same folder as the file you are trying to open.

If your file uses ANSI or the so-called "OEM" character set (i.e. doesn't
use Unicode or any other encoding), and uses CRLF record delimiters and " as
a text delimiter, you can probably open it using ODBC.

To use (c),
d. the ODBC text driver must be installed on the machine where you're doing
the merge
e. you need either a machine (user/system) ODBC DSN or file DSN
f. your OpenDataSource wil lneed to be something like

OpenDataSource _
Name:="", _
Connection:="DSN=yourtextfiledsnname;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

for a machine DSN and

OpenDataSource _
Name:="pathnameofyourdsnfile.dsn", _
Connection:="FILEDSN=pathnameofyourdsnfile.dsn;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

You may also see other dialogs concerning text encoding and so on.

In short, this isn't a particularly good file format to use in order to
automate a Word merge. If you can, use ADOX and ADO to create and populate a
table in a Jet database instead.

Peter Jamieson

"ksg" wrote in message
news
I am writing an application that will accept pipe "|" delimited text files
from other applications to be mail merged when receive. I can pick the
files
up from the directory, open the main mail document and open the data
source;
however when the opendatasource command is executed a dialog box pops up
asking "Text File Connection Properties". I need to pass all the
information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio - Visual
Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal formfilename As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile





  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ksg ksg is offline
external usenet poster
 
Posts: 13
Default Automated Mail Merge Displaying unwanted Dialog Boxes

Peter thanks for the quick reply.

Would you be able to point to a place where I can see an example of how to
use ADOX and ADO to create and populate a table in a Jet database.
Thanks
ksg

"Peter Jamieson" wrote:

Word can use at least three different methods to open a plain text file for
use as a data source:
a. its internal text converter. This will pop up a dialog if it doesn't
recognise the field delimiters. There's no way to specify the delimiters in
the OpenDataSource call
b. an OLEDB text provider. This will also typically throw up a prompt
(probably twice, for some reason) for the field delimiter. Again, there is
no way to specify the delimiter in the OpenDataSource call or, as far as I
know, in the OLEDB connection string.
c. an ODBC text driver. In this case, you can specify some of the
characteristics of the file in a SCHEMA.INI file that the driver expects to
find in the same folder as the file you are trying to open.

If your file uses ANSI or the so-called "OEM" character set (i.e. doesn't
use Unicode or any other encoding), and uses CRLF record delimiters and " as
a text delimiter, you can probably open it using ODBC.

To use (c),
d. the ODBC text driver must be installed on the machine where you're doing
the merge
e. you need either a machine (user/system) ODBC DSN or file DSN
f. your OpenDataSource wil lneed to be something like

OpenDataSource _
Name:="", _
Connection:="DSN=yourtextfiledsnname;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

for a machine DSN and

OpenDataSource _
Name:="pathnameofyourdsnfile.dsn", _
Connection:="FILEDSN=pathnameofyourdsnfile.dsn;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

You may also see other dialogs concerning text encoding and so on.

In short, this isn't a particularly good file format to use in order to
automate a Word merge. If you can, use ADOX and ADO to create and populate a
table in a Jet database instead.

Peter Jamieson

"ksg" wrote in message
news
I am writing an application that will accept pipe "|" delimited text files
from other applications to be mail merged when receive. I can pick the
files
up from the directory, open the main mail document and open the data
source;
however when the opendatasource command is executed a dialog box pops up
asking "Text File Connection Properties". I need to pass all the
information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio - Visual
Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal formfilename As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile






  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Automated Mail Merge Displaying unwanted Dialog Boxes

These are not particularly good examples, but...

For creating an Access database (it's actually a .NET example but I think it
will translate into VB/VBA fairly easily), try

http://support.microsoft.com/kb/317867

For creating tables in an Access database, see

http://support.microsoft.com/kb/252908

For populating with data try the following (even though it's populating an
Excel table, it's still using ADO)

http://support.microsoft.com/kb/303814/

Peter Jamieson

"ksg" wrote in message
...
Peter thanks for the quick reply.

Would you be able to point to a place where I can see an example of how to
use ADOX and ADO to create and populate a table in a Jet database.
Thanks
ksg

"Peter Jamieson" wrote:

Word can use at least three different methods to open a plain text file
for
use as a data source:
a. its internal text converter. This will pop up a dialog if it doesn't
recognise the field delimiters. There's no way to specify the delimiters
in
the OpenDataSource call
b. an OLEDB text provider. This will also typically throw up a prompt
(probably twice, for some reason) for the field delimiter. Again, there
is
no way to specify the delimiter in the OpenDataSource call or, as far as
I
know, in the OLEDB connection string.
c. an ODBC text driver. In this case, you can specify some of the
characteristics of the file in a SCHEMA.INI file that the driver expects
to
find in the same folder as the file you are trying to open.

If your file uses ANSI or the so-called "OEM" character set (i.e. doesn't
use Unicode or any other encoding), and uses CRLF record delimiters and "
as
a text delimiter, you can probably open it using ODBC.

To use (c),
d. the ODBC text driver must be installed on the machine where you're
doing
the merge
e. you need either a machine (user/system) ODBC DSN or file DSN
f. your OpenDataSource wil lneed to be something like

OpenDataSource _
Name:="", _
Connection:="DSN=yourtextfiledsnname;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

for a machine DSN and

OpenDataSource _
Name:="pathnameofyourdsnfile.dsn", _
Connection:="FILEDSN=pathnameofyourdsnfile.dsn;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

You may also see other dialogs concerning text encoding and so on.

In short, this isn't a particularly good file format to use in order to
automate a Word merge. If you can, use ADOX and ADO to create and
populate a
table in a Jet database instead.

Peter Jamieson

"ksg" wrote in message
news
I am writing an application that will accept pipe "|" delimited text
files
from other applications to be mail merged when receive. I can pick the
files
up from the directory, open the main mail document and open the data
source;
however when the opendatasource command is executed a dialog box pops
up
asking "Text File Connection Properties". I need to pass all the
information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio - Visual
Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal formfilename
As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile








  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Automated Mail Merge Displaying unwanted Dialog Boxes

Incidentally, another route you can pursue is to try to set up your text
file as a table linked to an Access database. however, I don't know how you
would specify the delimiters (you can probably do it in Access but not sure
if you use ADOX) and there may be other issues.

Peter Jamieson

"ksg" wrote in message
...
Peter thanks for the quick reply.

Would you be able to point to a place where I can see an example of how to
use ADOX and ADO to create and populate a table in a Jet database.
Thanks
ksg

"Peter Jamieson" wrote:

Word can use at least three different methods to open a plain text file
for
use as a data source:
a. its internal text converter. This will pop up a dialog if it doesn't
recognise the field delimiters. There's no way to specify the delimiters
in
the OpenDataSource call
b. an OLEDB text provider. This will also typically throw up a prompt
(probably twice, for some reason) for the field delimiter. Again, there
is
no way to specify the delimiter in the OpenDataSource call or, as far as
I
know, in the OLEDB connection string.
c. an ODBC text driver. In this case, you can specify some of the
characteristics of the file in a SCHEMA.INI file that the driver expects
to
find in the same folder as the file you are trying to open.

If your file uses ANSI or the so-called "OEM" character set (i.e. doesn't
use Unicode or any other encoding), and uses CRLF record delimiters and "
as
a text delimiter, you can probably open it using ODBC.

To use (c),
d. the ODBC text driver must be installed on the machine where you're
doing
the merge
e. you need either a machine (user/system) ODBC DSN or file DSN
f. your OpenDataSource wil lneed to be something like

OpenDataSource _
Name:="", _
Connection:="DSN=yourtextfiledsnname;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

for a machine DSN and

OpenDataSource _
Name:="pathnameofyourdsnfile.dsn", _
Connection:="FILEDSN=pathnameofyourdsnfile.dsn;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

You may also see other dialogs concerning text encoding and so on.

In short, this isn't a particularly good file format to use in order to
automate a Word merge. If you can, use ADOX and ADO to create and
populate a
table in a Jet database instead.

Peter Jamieson

"ksg" wrote in message
news
I am writing an application that will accept pipe "|" delimited text
files
from other applications to be mail merged when receive. I can pick the
files
up from the directory, open the main mail document and open the data
source;
however when the opendatasource command is executed a dialog box pops
up
asking "Text File Connection Properties". I need to pass all the
information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio - Visual
Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal formfilename
As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile










  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ksg ksg is offline
external usenet poster
 
Posts: 13
Default Automated Mail Merge Displaying unwanted Dialog Boxes

Thanks Peter. I will review those links and let you know what happens.

Again thanks for the quick response.

Happy Holidays!

"Peter Jamieson" wrote:

Incidentally, another route you can pursue is to try to set up your text
file as a table linked to an Access database. however, I don't know how you
would specify the delimiters (you can probably do it in Access but not sure
if you use ADOX) and there may be other issues.

Peter Jamieson

"ksg" wrote in message
...
Peter thanks for the quick reply.

Would you be able to point to a place where I can see an example of how to
use ADOX and ADO to create and populate a table in a Jet database.
Thanks
ksg

"Peter Jamieson" wrote:

Word can use at least three different methods to open a plain text file
for
use as a data source:
a. its internal text converter. This will pop up a dialog if it doesn't
recognise the field delimiters. There's no way to specify the delimiters
in
the OpenDataSource call
b. an OLEDB text provider. This will also typically throw up a prompt
(probably twice, for some reason) for the field delimiter. Again, there
is
no way to specify the delimiter in the OpenDataSource call or, as far as
I
know, in the OLEDB connection string.
c. an ODBC text driver. In this case, you can specify some of the
characteristics of the file in a SCHEMA.INI file that the driver expects
to
find in the same folder as the file you are trying to open.

If your file uses ANSI or the so-called "OEM" character set (i.e. doesn't
use Unicode or any other encoding), and uses CRLF record delimiters and "
as
a text delimiter, you can probably open it using ODBC.

To use (c),
d. the ODBC text driver must be installed on the machine where you're
doing
the merge
e. you need either a machine (user/system) ODBC DSN or file DSN
f. your OpenDataSource wil lneed to be something like

OpenDataSource _
Name:="", _
Connection:="DSN=yourtextfiledsnname;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

for a machine DSN and

OpenDataSource _
Name:="pathnameofyourdsnfile.dsn", _
Connection:="FILEDSN=pathnameofyourdsnfile.dsn;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

You may also see other dialogs concerning text encoding and so on.

In short, this isn't a particularly good file format to use in order to
automate a Word merge. If you can, use ADOX and ADO to create and
populate a
table in a Jet database instead.

Peter Jamieson

"ksg" wrote in message
news I am writing an application that will accept pipe "|" delimited text
files
from other applications to be mail merged when receive. I can pick the
files
up from the directory, open the main mail document and open the data
source;
however when the opendatasource command is executed a dialog box pops
up
asking "Text File Connection Properties". I need to pass all the
information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio - Visual
Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal formfilename
As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile









  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ksg ksg is offline
external usenet poster
 
Posts: 13
Default Automated Mail Merge Displaying unwanted Dialog Boxes

Hi Peter,
I finally got back to this project. I covert the .txt file to a .xls when I
recieve the file and everything works great.

Thanks for you help on this problem.

I now have an issue where I am getting a dialog box about saving the
normal.dot file after every merge. I deleted the normal.dot file in case it
was corrupted and it ran fine the first time, but the next time I got the
same message. Any ideas on how to get rid of the message?

Thanks
ksg

"Peter Jamieson" wrote:

Incidentally, another route you can pursue is to try to set up your text
file as a table linked to an Access database. however, I don't know how you
would specify the delimiters (you can probably do it in Access but not sure
if you use ADOX) and there may be other issues.

Peter Jamieson

"ksg" wrote in message
...
Peter thanks for the quick reply.

Would you be able to point to a place where I can see an example of how to
use ADOX and ADO to create and populate a table in a Jet database.
Thanks
ksg

"Peter Jamieson" wrote:

Word can use at least three different methods to open a plain text file
for
use as a data source:
a. its internal text converter. This will pop up a dialog if it doesn't
recognise the field delimiters. There's no way to specify the delimiters
in
the OpenDataSource call
b. an OLEDB text provider. This will also typically throw up a prompt
(probably twice, for some reason) for the field delimiter. Again, there
is
no way to specify the delimiter in the OpenDataSource call or, as far as
I
know, in the OLEDB connection string.
c. an ODBC text driver. In this case, you can specify some of the
characteristics of the file in a SCHEMA.INI file that the driver expects
to
find in the same folder as the file you are trying to open.

If your file uses ANSI or the so-called "OEM" character set (i.e. doesn't
use Unicode or any other encoding), and uses CRLF record delimiters and "
as
a text delimiter, you can probably open it using ODBC.

To use (c),
d. the ODBC text driver must be installed on the machine where you're
doing
the merge
e. you need either a machine (user/system) ODBC DSN or file DSN
f. your OpenDataSource wil lneed to be something like

OpenDataSource _
Name:="", _
Connection:="DSN=yourtextfiledsnname;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

for a machine DSN and

OpenDataSource _
Name:="pathnameofyourdsnfile.dsn", _
Connection:="FILEDSN=pathnameofyourdsnfile.dsn;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

You may also see other dialogs concerning text encoding and so on.

In short, this isn't a particularly good file format to use in order to
automate a Word merge. If you can, use ADOX and ADO to create and
populate a
table in a Jet database instead.

Peter Jamieson

"ksg" wrote in message
news I am writing an application that will accept pipe "|" delimited text
files
from other applications to be mail merged when receive. I can pick the
files
up from the directory, open the main mail document and open the data
source;
however when the opendatasource command is executed a dialog box pops
up
asking "Text File Connection Properties". I need to pass all the
information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio - Visual
Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal formfilename
As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile









  #8   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Automated Mail Merge Displaying unwanted Dialog Boxes

One thing I notice in your code is that you are not doing a

wrdApp.Quit

I'd try that first. Otherwise, my best guess is that you already have an
instance of winword.exe running when you call your CreateObject and you may
need to messa round with GetObject first.

Peter Jamieson
"ksg" wrote in message
...
Hi Peter,
I finally got back to this project. I covert the .txt file to a .xls when
I
recieve the file and everything works great.

Thanks for you help on this problem.

I now have an issue where I am getting a dialog box about saving the
normal.dot file after every merge. I deleted the normal.dot file in case
it
was corrupted and it ran fine the first time, but the next time I got the
same message. Any ideas on how to get rid of the message?

Thanks
ksg

"Peter Jamieson" wrote:

Incidentally, another route you can pursue is to try to set up your text
file as a table linked to an Access database. however, I don't know how
you
would specify the delimiters (you can probably do it in Access but not
sure
if you use ADOX) and there may be other issues.

Peter Jamieson

"ksg" wrote in message
...
Peter thanks for the quick reply.

Would you be able to point to a place where I can see an example of how
to
use ADOX and ADO to create and populate a table in a Jet database.
Thanks
ksg

"Peter Jamieson" wrote:

Word can use at least three different methods to open a plain text
file
for
use as a data source:
a. its internal text converter. This will pop up a dialog if it
doesn't
recognise the field delimiters. There's no way to specify the
delimiters
in
the OpenDataSource call
b. an OLEDB text provider. This will also typically throw up a prompt
(probably twice, for some reason) for the field delimiter. Again,
there
is
no way to specify the delimiter in the OpenDataSource call or, as far
as
I
know, in the OLEDB connection string.
c. an ODBC text driver. In this case, you can specify some of the
characteristics of the file in a SCHEMA.INI file that the driver
expects
to
find in the same folder as the file you are trying to open.

If your file uses ANSI or the so-called "OEM" character set (i.e.
doesn't
use Unicode or any other encoding), and uses CRLF record delimiters
and "
as
a text delimiter, you can probably open it using ODBC.

To use (c),
d. the ODBC text driver must be installed on the machine where you're
doing
the merge
e. you need either a machine (user/system) ODBC DSN or file DSN
f. your OpenDataSource wil lneed to be something like

OpenDataSource _
Name:="", _
Connection:="DSN=yourtextfiledsnname;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

for a machine DSN and

OpenDataSource _
Name:="pathnameofyourdsnfile.dsn", _
Connection:="FILEDSN=pathnameofyourdsnfile.dsn;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

You may also see other dialogs concerning text encoding and so on.

In short, this isn't a particularly good file format to use in order
to
automate a Word merge. If you can, use ADOX and ADO to create and
populate a
table in a Jet database instead.

Peter Jamieson

"ksg" wrote in message
news I am writing an application that will accept pipe "|" delimited text
files
from other applications to be mail merged when receive. I can pick
the
files
up from the directory, open the main mail document and open the data
source;
however when the opendatasource command is executed a dialog box
pops
up
asking "Text File Connection Properties". I need to pass all the
information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio -
Visual
Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal
formfilename
As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile











  #9   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ksg ksg is offline
external usenet poster
 
Posts: 13
Default Automated Mail Merge Displaying unwanted Dialog Boxes

Thanks Peter

"Peter Jamieson" wrote:

One thing I notice in your code is that you are not doing a

wrdApp.Quit

I'd try that first. Otherwise, my best guess is that you already have an
instance of winword.exe running when you call your CreateObject and you may
need to messa round with GetObject first.

Peter Jamieson
"ksg" wrote in message
...
Hi Peter,
I finally got back to this project. I covert the .txt file to a .xls when
I
recieve the file and everything works great.

Thanks for you help on this problem.

I now have an issue where I am getting a dialog box about saving the
normal.dot file after every merge. I deleted the normal.dot file in case
it
was corrupted and it ran fine the first time, but the next time I got the
same message. Any ideas on how to get rid of the message?

Thanks
ksg

"Peter Jamieson" wrote:

Incidentally, another route you can pursue is to try to set up your text
file as a table linked to an Access database. however, I don't know how
you
would specify the delimiters (you can probably do it in Access but not
sure
if you use ADOX) and there may be other issues.

Peter Jamieson

"ksg" wrote in message
...
Peter thanks for the quick reply.

Would you be able to point to a place where I can see an example of how
to
use ADOX and ADO to create and populate a table in a Jet database.
Thanks
ksg

"Peter Jamieson" wrote:

Word can use at least three different methods to open a plain text
file
for
use as a data source:
a. its internal text converter. This will pop up a dialog if it
doesn't
recognise the field delimiters. There's no way to specify the
delimiters
in
the OpenDataSource call
b. an OLEDB text provider. This will also typically throw up a prompt
(probably twice, for some reason) for the field delimiter. Again,
there
is
no way to specify the delimiter in the OpenDataSource call or, as far
as
I
know, in the OLEDB connection string.
c. an ODBC text driver. In this case, you can specify some of the
characteristics of the file in a SCHEMA.INI file that the driver
expects
to
find in the same folder as the file you are trying to open.

If your file uses ANSI or the so-called "OEM" character set (i.e.
doesn't
use Unicode or any other encoding), and uses CRLF record delimiters
and "
as
a text delimiter, you can probably open it using ODBC.

To use (c),
d. the ODBC text driver must be installed on the machine where you're
doing
the merge
e. you need either a machine (user/system) ODBC DSN or file DSN
f. your OpenDataSource wil lneed to be something like

OpenDataSource _
Name:="", _
Connection:="DSN=yourtextfiledsnname;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

for a machine DSN and

OpenDataSource _
Name:="pathnameofyourdsnfile.dsn", _
Connection:="FILEDSN=pathnameofyourdsnfile.dsn;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

You may also see other dialogs concerning text encoding and so on.

In short, this isn't a particularly good file format to use in order
to
automate a Word merge. If you can, use ADOX and ADO to create and
populate a
table in a Jet database instead.

Peter Jamieson

"ksg" wrote in message
news I am writing an application that will accept pipe "|" delimited text
files
from other applications to be mail merged when receive. I can pick
the
files
up from the directory, open the main mail document and open the data
source;
however when the opendatasource command is executed a dialog box
pops
up
asking "Text File Connection Properties". I need to pass all the
information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio -
Visual
Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal
formfilename
As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile












Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
printing difficultiies using mail merge in word flybynight Mailmerge 1 December 3rd 06 06:58 PM
Editing Mail Merge Recipients Stan W. Mailmerge 8 May 4th 06 05:03 AM
ASP.NET - Excel - Mail Merge in Word causes "Data Link Properties" dialog to appear. [email protected] Mailmerge 1 April 18th 06 02:38 PM
mail merge with attachments AS Mailmerge 5 April 9th 05 09:49 AM
How to remove unwanted formatting in mail merge for cells witn no Jim Mailmerge 3 March 4th 05 08:13 AM


All times are GMT +1. The time now is 10:53 PM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"