cd4770
cd4770

Reputation: 23

Syntax for Word Automation in C#

I am trying to create a heavily formatted word document in C# using Word Automation. I am having trouble finding the syntax for many of the operations I would like to accomplish. I have tried using Word's ability to build macros, and then use the resulting code to create what I need, but because the macros are written in Visual Basic and am having trouble "translating" it to C#. Is there a repository for Word Automation syntax? I am familiar with the tutorials available through Microsoft's website.

Upvotes: 2

Views: 2942

Answers (4)

Stefan P.
Stefan P.

Reputation: 9519

Convert VBA to VB .Net and C#

Upvotes: 0

Stephen D. Oliver
Stephen D. Oliver

Reputation: 126

A great place to start is with the Word VBA Developer Reference. The Word object model doesn't change just because you're using C# so you can learn what objects do what in VBA and then when you move to C# you only (basically) need to learn syntax differences. Especially with VS 2010 and dynamics, you don't have to do as much in the way of casting as before and the code is more like VBA (in a way).

Try out the Word Developer Resource center for all things Word developer.

Upvotes: 0

winwaed
winwaed

Reputation: 7801

Use the Word COM model reference. Here's the one for Word 2007:

http://msdn.microsoft.com/en-us/library/bb225019%28office.12%29.aspx

I've had similar issues with Excel, and nothing beats a good book! (for Excel I use "Programming Excel with VBA and .NET" from O'Reilly).

Upvotes: 1

Doc Brown
Doc Brown

Reputation: 20044

IMHO there is no better reference than the macro recorder itself. If you have trouble translating VB to C#, this reference sheet might be helpful:

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

If you are using C# 3.5 or less, AFAIK there's no easy way to leave out parameters when calling functions from any of Word's COM objects. In this case, it might be an alternative to use VB.NET instead of C# for this task.

Upvotes: 0

Related Questions