Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
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 ![]() 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
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
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 ![]() 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
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
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 ![]() 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
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
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 ![]() 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 | |
|
|
![]() |
||||
Thread | Forum | |||
printing difficultiies using mail merge in word | Mailmerge | |||
Editing Mail Merge Recipients | Mailmerge | |||
ASP.NET - Excel - Mail Merge in Word causes "Data Link Properties" dialog to appear. | Mailmerge | |||
mail merge with attachments | Mailmerge | |||
How to remove unwanted formatting in mail merge for cells witn no | Mailmerge |