Hi all,
I have a problem automating word (office xp).
I am trying to create a mailmerge datasource using this code:
object oFieldsVector = (object)fieldsVector;
object oFileName = "doc123";//aDoc.Name;
aDoc.MailMerge.CreateDataSource(ref oFileName, ref missing, ref missing, ref
oFieldsVector, ref missing, ref missing, ref missing, ref missing, ref
missing);
aDoc.MailMerge.EditDataSource();
Word.Document aTable = WordApp.ActiveDocument;
Word.Table table = aTable.Tables.Item(1);
for (int j=1;j<dataSource.Rows.Count;j++)
{
table.Select();
table.Rows.Add(ref missing);
}
the problem is that when i get to the row adding part, a dialog opens up in
the word application asking something about the columns.
this issue never came up in all MS and others examples on the web.
did anyone see this too?
what am i doing wrong? (this is actually almost coppied from MSDN sample).
thanx,
Picho 5 5794
Picho,
Here is some sample code that I used in VB.NET for performing a mail merge.
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim wrdMailMerge As Word.MailMerge
Dim strDataFile As String
' Create an instance of Word and make it visible
wrdApp = CType(GetObject("", "Word.Application"), Word.Application)
wrdApp.Visible = True
' Open the template
wrdDoc = wrdApp.Documents.Open(TemplateName, False, True)
wrdMailMerge = wrdDoc.MailMerge
Call wrdMailMerge.OpenDataSource(FileName, 0, False, True)
wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument
wrdMailMerge.Execute(False)
' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wrdMailMerge)
wrdMailMerge = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wrdDoc)
wrdDoc = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wrdApp)
wrdApp = Nothing
GC.Collect()
"Picho" <pi***********@telhai.ac.il> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Hi all,
I have a problem automating word (office xp). I am trying to create a mailmerge datasource using this code:
object oFieldsVector = (object)fieldsVector;
object oFileName = "doc123";//aDoc.Name;
aDoc.MailMerge.CreateDataSource(ref oFileName, ref missing, ref missing,
ref oFieldsVector, ref missing, ref missing, ref missing, ref missing, ref missing);
aDoc.MailMerge.EditDataSource();
Word.Document aTable = WordApp.ActiveDocument;
Word.Table table = aTable.Tables.Item(1);
for (int j=1;j<dataSource.Rows.Count;j++)
{
table.Select();
table.Rows.Add(ref missing);
} the problem is that when i get to the row adding part, a dialog opens up
in the word application asking something about the columns.
this issue never came up in all MS and others examples on the web.
did anyone see this too?
what am i doing wrong? (this is actually almost coppied from MSDN sample). thanx, Picho
Thanx for the reply. I do know how to open a datasource and execute the
merge. the problem starts when I want to create an internal dataSource for
the new document.
Picho
"solex" <so***@nowhere.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... Picho,
Here is some sample code that I used in VB.NET for performing a mail
merge. Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Dim wrdMailMerge As Word.MailMerge Dim strDataFile As String ' Create an instance of Word and make it visible wrdApp = CType(GetObject("", "Word.Application"), Word.Application) wrdApp.Visible = True ' Open the template wrdDoc = wrdApp.Documents.Open(TemplateName, False, True) wrdMailMerge = wrdDoc.MailMerge Call wrdMailMerge.OpenDataSource(FileName, 0, False, True) wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument wrdMailMerge.Execute(False) ' Close the original form document wrdDoc.Saved = True wrdDoc.Close(False) System.Runtime.InteropServices.Marshal.ReleaseComO bject(wrdMailMerge) wrdMailMerge = Nothing System.Runtime.InteropServices.Marshal.ReleaseComO bject(wrdDoc) wrdDoc = Nothing System.Runtime.InteropServices.Marshal.ReleaseComO bject(wrdApp) wrdApp = Nothing GC.Collect()
"Picho" <pi***********@telhai.ac.il> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Hi all,
I have a problem automating word (office xp). I am trying to create a mailmerge datasource using this code:
object oFieldsVector = (object)fieldsVector;
object oFileName = "doc123";//aDoc.Name;
aDoc.MailMerge.CreateDataSource(ref oFileName, ref missing, ref missing, ref oFieldsVector, ref missing, ref missing, ref missing, ref missing, ref missing);
aDoc.MailMerge.EditDataSource();
Word.Document aTable = WordApp.ActiveDocument;
Word.Table table = aTable.Tables.Item(1);
for (int j=1;j<dataSource.Rows.Count;j++)
{
table.Select();
table.Rows.Add(ref missing);
} the problem is that when i get to the row adding part, a dialog opens up in the word application asking something about the columns.
this issue never came up in all MS and others examples on the web.
did anyone see this too?
what am i doing wrong? (this is actually almost coppied from MSDN
sample).
thanx, Picho
Hi Picho,
Which version of Word are you trying to automate? Do you have a particular
reason for wanting to use a Word table for the data source? Generally, a
delimited text source (which can be saved as a Word document) will do just as
well and will be faster to generate.
There are reasons for using Word tables:
- you want to include text formatting in the data source in the merge
- you want to include graphical objects in the data source
- you want to preserve leading or trailing spaces in the data
If none of the above apply, put your data together in delimited format, dump
it into a Word document (or a text file, but a Word doc is generally "safer"
across all versions of Word), save that and link it in as the data source. I have a problem automating word (office xp). I am trying to create a mailmerge datasource using this code:
object oFieldsVector = (object)fieldsVector;
object oFileName = "doc123";//aDoc.Name;
aDoc.MailMerge.CreateDataSource(ref oFileName, ref missing, ref missing, ref oFieldsVector, ref missing, ref missing, ref missing, ref missing, ref missing);
aDoc.MailMerge.EditDataSource();
Word.Document aTable = WordApp.ActiveDocument;
Word.Table table = aTable.Tables.Item(1);
for (int j=1;j<dataSource.Rows.Count;j++)
{
table.Select();
table.Rows.Add(ref missing);
} the problem is that when i get to the row adding part, a dialog opens up in the word application asking something about the columns.
this issue never came up in all MS and others examples on the web.
did anyone see this too?
what am i doing wrong? (this is actually almost coppied from MSDN sample).
-- Cindy
Thanx Cindy,
I thought that I can link a "virtual" dataSource to the Doc.
My app is supposed to open a new doc with a new dataSource.
otherwise the user will have to handle the savings of two files: the doc and
the datasource.
correct me if I am wrong, but it is impossible to do right?
Picho
"Cindy M -WordMVP-" <C.*********@hispeed.ch> wrote in message
news:VA.00008fd6.006149d2@speedy... Hi Picho,
Which version of Word are you trying to automate? Do you have a particular reason for wanting to use a Word table for the data source? Generally, a delimited text source (which can be saved as a Word document) will do just
as well and will be faster to generate.
There are reasons for using Word tables: - you want to include text formatting in the data source in the merge - you want to include graphical objects in the data source - you want to preserve leading or trailing spaces in the data
If none of the above apply, put your data together in delimited format,
dump it into a Word document (or a text file, but a Word doc is generally
"safer" across all versions of Word), save that and link it in as the data source.
I have a problem automating word (office xp). I am trying to create a mailmerge datasource using this code:
object oFieldsVector = (object)fieldsVector;
object oFileName = "doc123";//aDoc.Name;
aDoc.MailMerge.CreateDataSource(ref oFileName, ref missing, ref missing,
ref oFieldsVector, ref missing, ref missing, ref missing, ref missing, ref missing);
aDoc.MailMerge.EditDataSource();
Word.Document aTable = WordApp.ActiveDocument;
Word.Table table = aTable.Tables.Item(1);
for (int j=1;j<dataSource.Rows.Count;j++)
{
table.Select();
table.Rows.Add(ref missing);
} the problem is that when i get to the row adding part, a dialog opens up
in the word application asking something about the columns.
this issue never came up in all MS and others examples on the web.
did anyone see this too?
what am i doing wrong? (this is actually almost coppied from MSDN
sample).
-- Cindy
Hi Picho, I thought that I can link a "virtual" dataSource to the Doc. My app is supposed to open a new doc with a new dataSource. otherwise the user will have to handle the savings of two files: the doc and the datasource.
correct me if I am wrong, but it is impossible to do right?
I don't know of any way for you to create a "virtual data source", but you
should be able to link up the data source for the user, and save him that
step. CreateDataSource does NOT create a "virtual data source" - notice you
have to give it a file name? And EditDataSource actually opens the file
(again).
Think of your requirement as separate tasks, and work on each task
individually, until you get what you need:
- creating the data source
- opening or creating the main merge document
- linking the data source (OpenDataSource method)
- generating the main merge document content
- presenting the result to the user
When looked at like this, it doesn't matter WHAT you use for the data source,
as long as the version of Word you're automating supports linking to it using
OpenDataSource with no problems. Given everything I know about your project,
my recommendation would be:
- concatenate the data into a delimited string
- create a new Word document
- put the string into the Word document (doc.Range.Text = szString - worlds
faster than the approach proposed in your first message)
- save the document and close it
- create another new document
- use OpenDataSource to link to the data document
- insert the text and merge fields
-- Cindy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mickeydisn |
last post by:
Sub: C++ Word automation Extract text
hello.
I want extact text form a word document using a visual c++ programme.
I have see a lot of documentation. and my analysis is that I must use a...
|
by: Mike MacSween |
last post by:
Office 2000
From Access I've been starting an instance of word and doing a mail merge.
Everything hunky-dory until I applied SP1 yesterday.
Now this:
dim wrd as Object
set wrd =...
|
by: kids |
last post by:
Does anybody know any reason which could cause Ms. word automation to crash?
I try to call word automation to open a document and use find and replace
function.
For some reason it works but I...
|
by: Daniel |
last post by:
Hello,
i have a problem with the word automation from c#. First,
i want to mention, that i don't have any dependencies from
word in my c#-project, i want to use the system.reflection
model to...
|
by: Franck |
last post by:
hello,
I've found this tutorial for word automation in asp
http://www.codeproject.com/aspnet/wordapplication.asp
TO work I need to include the
"Microsoft Word 10.0 Object Library dll"
But...
|
by: Charles Law |
last post by:
Does anyone know which files need to be distributed with a VB.NET
application to enable Word automation on a m/c that does not have Word
installed? Is this even possible / permissible? I currently...
|
by: johnc |
last post by:
Hi all
Been struggling to get word automation working via ASP on the server.
The COM objects etc are installed and there already exists an Excel automation application which works, done by a...
|
by: Steve |
last post by:
I am trying to figure out how I can center and size a word application
active window within my vb.net form when the word document is open using
automation so that the word window doesn't extend...
|
by: apondu |
last post by:
Hi,
can someone help me and provide me the information on how to supress
the
default action of the shortcut keys of word during word automation.
I am using C#.Net
I have written a code but...
|
by: Pramod Elig |
last post by:
I developed this code which works fine in my current system which has office 2007, but when I run in word 2000 this doesn’t work. Can you please help me to code word automation using late binding. I...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |