Facing problem using Word.Find.Execute method

S

Santhosh

Hi,
I am working on creating a .doc file by using .dot(Template) file using
Word.ApplicationClass. In this process I am having few tags in the template
file which I am trying to replace with some content. But when I am trying to
insert large text as the replacement text, I am getting an error "String too
long".

Following are the piece of code that I am using:

private void button1_Click(object sender, System.EventArgs e)
{
WordDoc wd = new WordDoc();
wd.Open("D:\\PTS\\Test1.dot");
object str = textBox1.Text; // It is a multiline text box where large text
is inserted
wd.FindAndReplacement("<<Body>>", str);
wd.SaveAs("D:\\PTS\\Test.doc");
wd.Quit();
}

public void FindAndReplacement(string strFind, object strReplace)
{
Word.ApplicationClass oWordAppl = new Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
object story = Word.WdUnits.wdStory;
object ext = Word.WdMovementType.wdExtend;
object rp = Word.WdReplace.wdReplaceAll;
object strf = strFind;
object strr = strReplace;
oWordAppl.Selection.HomeKey(ref story,ref ext);
oWordAppl.Selection.Find.Execute(ref strf, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref strr, ref rp, ref missing,ref missing,ref missing, ref missing);
}

This code is however working for smaller texts. Please let me know if there
is anything wrong I m doing in this code. If the code is fine, then please
let me know how to fix the issue.

Note: I am using MS Word 2000 component in my C# aplication.

Thanx & regards,
Santhosh.B
 
H

Helmut Weber

Hi Santhosh,

the replacement string is limited to 255 characters.

Do You need help on a solution for longer strings,
or can You find out yourself, how to do it?

Maybe you even like to do it yourself. ;-)

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
S

Santhosh

Hi,
Thank you very much for the early reply.
My requirement is that I want to create a word document based on the inputs
given in a form. For ex: I have a form with the controls taking Header, Body
& footer details. I want to know which is the better way to create it. I have
couple of options in mind. Please let me know if any of the following
approach is fine or if there is any issues if I use any of these approach or
if there is any other way to achieve it.

1. I have text box controls that gets me Header, Body & Footer details and
then using these data, I go ahead and create a word document.
The issue with this approach is that I cannot use more than one formatting
techniques.
2. I use a .Net OCX component called DSO Framer with which I am free to
create any word document using all kinds of formatting.
The issue with this approach is that I am not able to disable just the
"save", "open", etc buttons individually.

Please let me know what I can do so that I can create the Body content using
DSO Framer kind of Active X controls and then add Header & Footer to that
content.

Thanks & Regards,
Santhosh.B
 
H

Helmut Weber

Hi Santosh,
1. I have text box controls that gets me Header, Body & Footer details and
then using these data, I go ahead and create a word document.
The issue with this approach is that I cannot use more than one formatting
techniques.

Why? What is a formatting technique?

Once you have a word document, all kinds of formatting should be possible.
2. I use a .Net OCX component called DSO Framer

I'm not competent in this field, sorry.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
S

Santhosh

Hi,

I need to access the content of a given MS Word file.

For example the content is like this:
abcdefg
xyz
123

The file has 3 lines, and I need to get the 2nd line's value, in this case
"xyz".

Does anybody know how to do that? I have added the library and tried to do
it however it just can't seem to work. Really need an expert's help...

Thanks,
Santhosh
 
D

Doug Robbins

Assuming that the lines are separate pargraphs, use:

ActiveDocument.Paragraphs(2).Range


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top