473,756 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a little help in word automation

Regards,
I need a little explanation in converting word VB macros to charp code!

first, I recorded simple macro which replaces every occurence of one word in
whole document (is it?) , here:

Sub replaceall()
'
Selection.Find. ClearFormatting
Selection.Find. Replacement.Cle arFormatting
With Selection.Find
.Text = "original"
.Replacement.Te xt = "replacemen t"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLik e = False
.MatchAllWordFo rms = False
End With
Selection.Find. Execute Replace:=wdRepl aceAll
End Sub

Now..

my code in csharp looks like that:

Word.Applicatio nClass WordApp = new Word.Applicatio nClass();
object fileName = System.Environm ent.CurrentDire ctory + \\proc.doc;
object missing = System.Reflecti on.Missing.Valu e;
WordApp.Visible = true;
// Open the document that was chosen by the dialog
Word.Document aDoc = WordApp.Documen ts.Open(ref fileName, ref missing,ref
readOnly, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref isVisible);
// Activate the document so it shows up in front
aDoc.Activate() ;
WordApp.ActiveW indow.Selection .Find.ClearForm atting();
WordApp.ActiveW indow.Selection .Find.Replaceme nt.ClearFormatt ing();
WordApp.ActiveW indow.Selection .Find.Text = "original";
WordApp.ActiveW indow.Selection .Find.Replaceme nt.Text = "replacemen t";
WordApp.ActiveW indow.Selection .Find.Forward = true;
WordApp.ActiveW indow.Selection .Find.Wrap = Word.WdFindWrap .wdFindContinue ;
WordApp.ActiveW indow.Selection .Find.Format = false;
WordApp.ActiveW indow.Selection .Find.MatchCase = false;
WordApp.ActiveW indow.Selection .Find.MatchWhol eWord = false;
WordApp.ActiveW indow.Selection .Find.MatchWild cards = false;
WordApp.ActiveW indow.Selection .Find.MatchSoun dsLike = false;
WordApp.ActiveW indow.Selection .Find.MatchAllW ordForms = false;
WordApp.ActiveW indow.Selection .Find.Execute(r ef missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, Word.WdReplace. wdReplaceAll, ref missing, ref
missing,ref missing,ref missing);

I get this error:

c:\documents and settings\admini strator\my documents\visua l studio
projects\borise xcel\form1.cs(3 88,5): error CS1502: The best overloaded
method match for 'Word.Find.Exec ute(ref object, ref object, ref object, ref
object, ref object, ref object, ref object, ref object, ref object, ref
object, ref object, ref object, ref object, ref object, ref object)' has
some invalid arguments
So what would be the best structure of code in CSharp (and it has to
compile, too :))

Searching on the net I get a lot of results but mostly in VB.NET (and I
don't know how to translate them, like you can see) and some in C# (here
always something doesn't work)..

THANK YOU!!

David
Nov 15 '05 #1
0 2894

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12087
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 "word automation". I have foud a lot of exemple to use it but I need your precious help to
12
5527
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000 and office XP components installed. ie I have word/access/excel 2k/xp/2003 installed. I tried to do a usual access 2k to word 2k automation yet I get the error "Automation Error" "ClassFactory cannot supply requested class" when on late binding try...
6
3960
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would open all four PPT files at once, and would loop through queriers for ever client and create custom presentations. Now there are 8 files, nearly 500 slides and the computer is bogging down with trying to open them all at once. I know that Access...
2
2614
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 don't know why it crash some time.
4
7682
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 handle the automation. So, i'm using the following code to create a new word document: ---Code---
2
2623
by: Radek | last post by:
Hi, I have got such problem: in my directory "C:\folder" I have 3 files in MS WORD (having tables, images etc), these are: "1.doc", "2.doc", "3.doc". I want to write an application (C# of course) which will merge the contents of files which I will point ie. 1.doc and 2.doc into one file: "12.doc" I've just tried to find smth in MSDN help, and in google archive of programing groups but still I don't know how to do it:(
4
11134
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone done this? Does it seem possible? I followed the instructions from a sample on the Microsoft knowledge base but it only seems to work when creating a VB.NET Windows .EXE, not an VB.NET ASP app.
5
2527
by: Daniel Walzenbach | last post by:
Hi, I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed). The preferable solution would be to have a word template on the server which is populated in the asp.net application and then streamed out to the user. Also acceptable would be to open a template on the client's computer using automation and fill this file (if this is possible)....
10
3283
by: cj2 | last post by:
I open a word template in VB and add values to the bookmarks then save the document as as pdf. When I then go to close the document it pops up a save as dialog box. It's already saved the document in pdf and that is all I want done with it. How can I tell it to close the file without prompting me for anything? For Each row As DataRow In myDt.Rows Dim objWord As Application Dim objDoc As Document objWord =...
0
10014
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3780
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.