Click here to Skip to main content
15,881,803 members
Everything / Productivity Apps and Services / Microsoft Office / Microsoft Word

Microsoft Word

MS-Word

Great Reads

by Mario Z
Pure .NET solution for performing find and replace text on Word documents (DOCX file format)
by koolprasad2003
This article explain you How to protect word document using C# and Word automation
by Reiss
This is an alternative for "How to Check Whether Word is Installed in the System or Not"
by koolprasad2003
This tip gives you an idea about how to create Word table using C# (Word automation)

Latest Articles

by William Damert
Console .NET application using Microsoft.Office.Interop.Word for keyword search
by stc.reseller
Helpful tips in labeling Office files or how to make Office file changes statistically visible, in one single step
by Jose A Pascoa
Although most Windows programmers have already used the RichEdit Control, many of them are not aware of all its capabilities. One such capability is image embedding.
by Member 12994860
Change the Font Color of all Equations in a Word Document

All Articles

Sort by Score

Microsoft Word 

14 Jun 2016 by Mario Z
Pure .NET solution for performing find and replace text on Word documents (DOCX file format)
24 Nov 2015 by koolprasad2003
This article explain you How to protect word document using C# and Word automation
24 Dec 2013 by Reiss
This is an alternative for "How to Check Whether Word is Installed in the System or Not"
20 Apr 2015 by Mario Z
Hi, try this:var application = new Application();var document = application.Documents.Open(FileName: @"C:\Sample In.docx");var tocRange = document.Range(0, 0);var toc = document.TablesOfContents.Add( Range: tocRange, UseHeadingStyles: true);toc.Update();var...
13 Sep 2014 by koolprasad2003
This tip gives you an idea about how to create Word table using C# (Word automation)
22 Oct 2014 by D. Forbes
Switching from native Word to Aspose's .Words component stabilized our server, and improved the speed of our product.
29 Nov 2011 by Manoj K Bhoir
Use the following code : Dim strSearchWords As String = "I like apple"Dim sarySearchWord As String()sarySearchWord = Split(Trim(strSearchWords), " ")MsgBox("Number of words = " & sarySearchWord.LengthYou can Search these words by Swaping :Dim s1 As String =...
18 Dec 2016 by NightWizzard
Convert amounts to their spoken equivalents
23 Mar 2011 by OriginalGriff
Access provides autonumber: it is called an "autoNumber" field, surprise, surprise. Also unsurprisingly, it is numeric only...I would keep the Voucher code separate: The Voucher number is the Autonumber field, the Date field is the TodayDate, and build the voucher code from that using...
28 Apr 2011 by Nish Nishant
Each version of the COM library will most likely have access to only those instances from the same version. So if you have 2 versions of Office, you'll probably need to COM interop with them separately.[Update]~~~~~~~~~~In response to your comment:Yeah you'll need separate...
7 May 2011 by IncredibleRam
hello there following links may help you sort out your problem.Convert Office Word Document to HTML and display it in browser in ASP.NetFile Denial - Let authorized users download files from your site - and keep unauthorized users out!Protect Your Downloadable Files Using HTTP...
22 May 2011 by Espen Harlinn
Apart from Abhinav S reference: if your application is executing as a 64-bit process you will run into trouble as Word 2007 is a 32-bit program ...Best regardsEspen Harlinn
24 Oct 2013 by Marc Gabrie
Just try Google Doc Viewer. It's very simple to use, free & you do not need any external tool nor dll! Add a markup code like the following in your webpage:Just set "url" query string param to your Word doc file as an absolute URI and that's it!
8 Oct 2014 by Maciej Los
I'd suggest to read this:How to recover a lost Word document [^]Use the Document Recovery task pane to recover your files[^]How to recover a lost file in Word 2007 or in Word 2003[^]Here is very interesting video tutorial: https://www.youtube.com/watch?v=4yTIn0kka80[^]You can use...
2 Jul 2016 by Six Hat Solutions
Easily Send Emails From Your Microsoft Applications Using VBA and the SendGrid API
27 Dec 2016 by #realJSOP
Here are the appropriate methids to use for conversion in both directions:System.Drawing.ColorTranslator.ToOLE(System.Drawing.Color)System.Drawing.ColorTranslator.FromOLE(int)
28 Oct 2019 by stc.reseller
Helpful tips in labeling Office files or how to make Office file changes statistically visible, in one single step
17 Jan 2011 by OriginalGriff
If you are saying that you want to build a web site that can read a word document, and display (and presumably edit) it exactly as it would be in word, then I'm afraid you have a lot of work to do. And I do mean a lot. As in a couple of million man-hours (that is an educated guess, but it won't...
9 Mar 2011 by Sergey Alexandrovich Kryukov
As you're new to the topic, I'm not sure you need exactly Word automation, which is only one approach to Word-related programming. Better start from this point: http://msdn.microsoft.com/en-us/library/ee342218.aspx[^].—SA
19 Mar 2011 by OriginalGriff
No.If the client needs Word to use your software, then it must be installed - and paid for! :laugh:
30 Mar 2011 by Espen Harlinn
You've developed a Word Addin which is connecting to DB and can add results to word document. As Word is a desktop application, and your addin requires Word it sound like you're out of luck unless you consider redoing it as a Sharepoint part. Inserting something from a database into a word...
5 Apr 2011 by Slacker007
I don't think you can "import" a macro from another document into a separate document on the fly.I could be off based here but don't you want to create a Word Template with the macro in this template and then when you create a new Word Doc (through your C# code) based on this new template.
6 Apr 2011 by Tarun.K.S
Here is a way to open a word document : Add a COM reference : Microsoft Office 12.0 Object LibraryThen add the following namespace : using Microsoft.Office;using office = Microsoft.Office.Interop.Word;And then in the code where you want to use, add this : var wordApp =...
21 Apr 2011 by R. Hoffmann
Disclaimer: I'm using Office 2010 (I don't have 2000), with VS 2010 & .NET 4.0 (C#). My Word interop is rusty, so please don't interpret my techniques as best practices. Nevertheless, I hope this may be useful.It would seem that the line that is created by wrdDoc.Shapes.AddLine is created on...
22 Apr 2011 by 2000 P
Could some one help me for this problem?Thanks!//My requirement is : Inserting external objects in to the word and PPT document using C#. Inserting Menu should show all opened word and PPT documents. Here I am not able to get word's instance/document name. For PPT we can use ppApp = new...
1 Nov 2011 by Mehdi Gholam
Line editing in Word is all or nothing, try using InfoPath for your requirements.
29 Nov 2011 by LanFanNinja
Here is my new solution for you using Heap's algorithm to determine all possible permutations of your input string. Please leave me a comment and let me know how it worked for you. Marking this as an answer would be nice too. :)EDIT: changed from C# to VB (I forgot) :)Private Sub...
2 Apr 2012 by OriginalGriff
I think perhaps you have mixed code from two sites: Word._Document.SaveAs takes 16 parameters: MSDN[^] (and so does the Word.Document.SaveAs which is the one I would expect to use).Go back to the site you got the code from, and look more closely - I think you have missed something! If...
1 Jan 2013 by Sander Rossel
What you're doing here is deleting lines while NP6% is still found in your document. Since you're deleting lines one by one it's no wonder all the lines up until the line with %NP6% are deleted. Once %NP6% is deleted the deleting will stop.Instead you should try looping through the Sentences...
9 May 2013 by Dave Kreskowiak
Or, you could just do the entire thing in Word. What you're describing is called "Mail Merge" and you can print the entire document to a PDF "printer" without a single line of code.
10 May 2013 by Sergey Alexandrovich Kryukov
I can see at least one problem: indirect recursion (http://en.wikipedia.org/wiki/Recursion[^]).When you call Navigate, your browser gets to loading the another document, which leads to invocation of your Load event again. Recursion is "infinite". You need to isolate the case of navigation to...
10 May 2013 by Sergey Alexandrovich Kryukov
OK, I took some time and got the complete solution for you. It was easy and worked from the first attempt!You just ignored some of my words. Did I tell you to use another event and cancel redirection to "href="https://docs.google.com/viewer?url=..."? Also, pay attention: this URL is...
29 May 2013 by Maciej Los
Have a look here:How to: Programmatically Add Text and Formatting to Cells in Word Tables[^]How to: Programmatically Insert Text into Word Documents[^]How to: Insert Text into Word Documents[^]A few other links that could be helpful:Walkthrough: Creating a Table in Word[^]How to:...
17 Dec 2013 by Sergey Alexandrovich Kryukov
Please see my comment to the question: it may or may not make sense, depending on what you are doing. In the meanwhile, read on the "compatibility...
11 Mar 2014 by Bob@work
It depends on the version of Word(r) you're wanting to target. For the old .DOC files, Microsoft has a robust interop assembly, but it needs to reside on the computer/server running the tasks. This may present security concerns for public-facing machines.For the new .DOCX files, I was able...
16 Nov 2014 by Kornfeld Eliyahu Peter
Word document do not contain pages, but a text flow...The Page[^] object you can find in the Word Object Model[^] does not represent a container, but a visual block of formatting.The Page as container of part of the content get meaning only after the actual rendering (visualization) of the...
21 Jul 2015 by Richard Deeming
VB6 was notoriously bad at enforcing variable types - it would jump through invisible hoops to try to stuff data of one type into a variable of a different type, often incorrectly.C# is much stricter about type conversions, and in 99.9% of cases that's a good thing. In this particular case,...
11 Apr 2017 by CHill60
You have several options. Firstly you can enumerate all of the fonts installed on your system - see How to: Enumerate Installed Fonts[^] If you want to build your own enum, you can have descriptions with spaces like this (ref:c# - Can my enums have friendly names?[^]) //Requires using...
3 Feb 2019 by Maciej Los
Check this: Use a formula in a Word or Outlook table - Office Support[^] - RnCn/A1 references section. This might be helpful too: Insert Table Formulas in Word - Instructions and Video Lesson[^] Nested IF fields in Word 2010 -- How? - Microsoft Community[^] How to Create IF Fields in a...
16 Dec 2020 by CHill60
If you attempt to save any VBA code in a non-macro enabled type for any Office document you will get an error. The file can still be saved, but not with the macros. You have very few choices 1. Not have any macros 2. Save in the latest version of...
24 Jan 2011 by marcoAntoniorubio
how to use OpenXML with word 2007 template?I want to replace the template markersand generate the documentin asp.net c #sorry for my English is very bad I'm learningHelp
8 Feb 2011 by Kizo1
Hello,As the title says, I need to embed a word .dotm template within a regular .doc/.docx file.The reason I need to do this is because there is a somewhat larger number of templates that my company has, and they are all share code that is located in one global template.The goal is to...
15 Feb 2011 by Abdul Quader Mamun
Thank you for your question, in MS Word 2007.Use:Insert>>Table>> Excel Spreadsheet>>(use like excel function).=CONCATENATE("-4.3",B1)Result is -4.332 where b1 equals to 32=CONCATENATE("-4.3",B2)Result is -4.345 where b2 equals to 45=CONCATENATE("-4.3",B3)Result is -4.365 where b3...
14 Mar 2011 by vivek_kapile_1980
HiFollow the step to show the data into a table1. Add a Table control on the ASPX page2. Add a code in .CS fileprivate void readFileContent(string path) { ...
1 Apr 2011 by pankajupadhyay29
check following links hope it will work for you--Using Custom XML Part as a data store[^]A discussion on msdn on same problem[^]
4 Apr 2011 by mpower88
I have this situation:I made an add-in for Word 2010 in visual studio 2010 (C#), which dynamicly adds new buttons to a new ribbon tab (data from sql database). Now when i click on a button, a new document with a macro needs to be opend. I have the needed macro in a document (.docm), and the...
18 Apr 2011 by Sandeep Mewara
Richtextbox type of controls are those control that allows HTML content in it and render it as per you need to. Have a look at the control here: AjaxToolkit: HTML Editor[^]jQuery: HTML Area[^]There are few more in market but are not free stuff. If you are unable to find on net, then...
18 Apr 2011 by Monjurul Habib
FCKeditor in ASP.NetCKeditor and ASP.NETCK Editor ASP.NET Wrapper DetailsCKEditor.NET Control Integration GuideI hope the above information will be helpful. If you have more concerns, please let me know.
22 Apr 2011 by Ankit Rajput
Hi,Please check itMicrosoft.Office.Interop.Word.Application objWord;objWord= (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");for (int i = 0; i
23 Apr 2011 by Sandeep Mewara
Web has lots[^] of tutorials and links for the sample. Few of them:XSLT Example[^]XSL Transformations (XSLT)[^]
26 Apr 2011 by Not Active
Writing reusable code rather than cut & paste the same thing over and over again is a good design and what you should strive for in all your software.
26 Apr 2011 by Nish Nishant
Whether it is feasible depends on how well your code works. But in general, yes, you should not have to repeat the same code in multiple places. Even twice is too many. So extracting a class/static method that does this would certainly be an improvement. In a UI scenario, you mght even want...
7 May 2011 by Wonde Tadesse
To be honest Microsoft Office automation is not recommended. Read Recommendation for sever side automation of Office[^].In order to view MS word online then you may have to go with third part controls. Like Telerik Editor control.[^]. It just like monster resume upload control. Or use google...
5 Jun 2011 by Sergey Alexandrovich Kryukov
You're doing it wrong. You assume 3 empty paragraphs (why? you need to detect them all), but you take one paragraph #3 instead. Why?!Take all paragraphs and enumerate them:using Microsoft.Office.Interop.Word;using ParagraphsList = ...
22 Jun 2011 by Maciej Los
You need to loop until Execute() is true.Do while objSelection.Find.Execute() 'code to make changes in textLoop
24 Jun 2011 by Dave Kreskowiak
Your code isn't writing a proper .DOC file for any version of Word. A .DOC file is not expected to contain HTML, but that's what you're writing out.My first suspect would be the UTF7 encoding. Change it to UTF8 and try it again.
26 Jun 2011 by Alimjan Yasin
I used the replacing methods, since I don't know how to save the format of word file ,it is better to analys it at sentences level and replace every single sentences by its translation. one more reason is there is no avaiable solution for that perpouse.
26 Jun 2011 by Slacker007
Every MS Office product has an object model. A table in a Word document is nothing more than an object of a class. Google the object model for a Word document and you will see a lot of hits for this...I don't know all of them off the top of my head. I usually do Office Automation through VBA...
12 Aug 2011 by #realJSOP
You mean something like this Codeproject article does:Anagrams - A Word Game in C#[^]
16 Aug 2011 by Bangla Gopal Surya Prakash
Hi Guys,I have window application running & this application has a form with a TextBox.And I want to build a Word 2007 Macro, Which will pass string from Macro to the running Windows Application & place it in TextBoxPlease help me with this regard.Thanks & Regards,Prakash
17 Aug 2011 by Sergey Alexandrovich Kryukov
Most difficult part is reading PDF. It's easier to find some SDK in Java or for .NET than in the form of a COM component. Anyway, there is a number of products, mostly commercial ones; try to find one:http://en.lmgtfy.com/?q=PDF+(ActiveX+OR+COM+OR+OCX)[^].Now, you will need to generate...
13 Sep 2011 by Prerak Patel
Hey Prasad,You can use HtmlEncode and then replace the white space characters using extension method.HtmlEncode is only meant to encode characters for display in HTML. It specifically does not encode whitespace characters. You could use String.Replace() to encode the newlines and spaces...
14 Sep 2011 by BobJanova
You should not convert all white space characters to non-breaking spaces. That will result in one huge, unbreakable line per paragraph! Also, your question has nothing to do with Unicode.If Word's default 'Save as HTML' is not sufficient for your requirements, you should write some macros...
20 Sep 2011 by Ajit Hegde
HiIf you are using wpf then check these linkshttp://blogs.msdn.com/b/wpf/archive/2010/08/03/introducing-microsoft-ribbon-for-wpf.aspx[^]http://www.codeproject.com/KB/WPF/ribboncontrol.aspx[^]http://wpf.codeplex.com/wikipage?title=WPF%20Ribbon%20Preview[^]
9 Nov 2011 by Trajan6
Just a little bit late, but I wouldn't do it with an external dependency like an XML-File.My suggestion is:private static void AddSettingsToMainDocumentPart(MainDocumentPart part) { DocumentSettingsPart settingsPart = part.AddNewPart(); settingsPart.Settings = new Settings( ...
10 Dec 2011 by thatraja
Fix linkReceiving “Path 'OPTIONS' is forbidden.” Exception in ASP.NET website[^]
26 Jan 2012 by Member 8586072
I have to write a program in java for wordwrap with minimum regard...for example if we have "aaa bb cc ddddd" and want to wrap it in lines with this method the final form should be like this :------ Line width: 6aaa Remaining space: 3 (cost = 3 squared = 9)bb cc Remaining...
1 Feb 2012 by masdhasdh
My mistake i didn't visited the comments there...remove EditId = "50D07946" from the code. will solve the issue but import with reduced size..Can anyone help me how to import that image in particular location in doc??Thanks.
8 Feb 2012 by coolyujw
I want to open a doc file by the way as follows;_Application wApp;wApp.CreateDispatch(L"Word.Application");Documents wDocs = wApp.GetDocuments();COleVariant vNotFind(DISP_E_PARAMNOTFOUND, VT_ERROR);_Document wDoc = wDocs.Open(COleVariant("...doc"),...
1 Mar 2012 by Richard MacCutchan
You need to use the Microsoft Word Interop assemblies[^].
6 Mar 2012 by andy(-RKO)
Hello All,I Want To Convert Tiff File To Word Using Asp.net C#. Can Any One Help Me..Please Reply Me ASAP..Thanx In Advance
2 Apr 2012 by wizardzz
double year = DateTime.Now.Year;string a = year.ToString();Will return 2012, so that trailing '1' is coming from somewhere else. I think digi is on to something, can you see if it happens on another page?
28 Apr 2012 by Maciej Los
I see one or two reasons:1) destination file extension is not correct!and/or2) SaveAs method doesn't specify FileFormat.Ad 1)Replace:Object oSaveAsFile = @"J:\\SampleDoc.doc";withObject oSaveAsFile = @"J:\\SampleDoc.docx";*.doc extension was used in MS Word 97-2003...
2 May 2012 by Eugene Polyhaev
Fully functional groovy template scriptlets inside a docx document
5 Aug 2012 by Rock3rRullz
Hi, I`m struggling to make this work, but till now i didn't found any answers on the web. Here is my problem, i have a doc file created on office 2003 and i have a table in it ( header and a first empty row ). How can i select that table from C# and add a new row in it? [ I populate the...
9 Aug 2012 by Kenneth Haugland
Here is the link:http://support.microsoft.com/kb/316383[^]Other supported Interops:http://msdn.microsoft.com/en-us/library/15s06t57.aspx[^]Now, off you go and program... ;)
13 Sep 2012 by pmcm
Hi - I have an application that when run in debug on my local machine has no problem opening this .dot file. But I've copied my application to a live server and when testing the app I get the following error message when trying to open the .dot file. This file is generated on a button click...
5 Mar 2013 by Andreas Gieriet
docx is Office Open XML[^] format.So, this has not directly to do with general purpose zip, but rather with the way office stores the file.C# provides the package class[^] to process such files.Please note that a package only understands the form, not the content. I.e. if you want to...
10 May 2013 by Sergey Alexandrovich Kryukov
This is because you don't really navigate to *.DOC. You need to start using the debugger, by the way.—SA
14 May 2013 by Sergey Alexandrovich Kryukov
For the server-side programming such as ASP.NET, prefer using Open XML SDK instead of Office Interop. Look at this Microsoft article:http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^].Use Open XML SDK:...
26 Jun 2013 by naveu2007
Hi all resolved my issue :):) thanks for the support..Just replaced the code as belowforeach (Word.ContentControl contentControl in document.ContentControls){ contentControl.Range.Text="Trial"; contentControl.Delete(false);}
15 Jul 2013 by zenspace
try this,http://social.msdn.microsoft.com/Forums/en-US/40e14cbe-6453-4971-8c72-5e4ee5205a5d/how-to-get-the-filename-of-a-winword-document[^]
13 Sep 2013 by Joan M
Solved it by myself...It is a little bit tricky and I've made a Tip&Trick and posted here in CP to allow anyone who would find him/herself into that situation to cope with it.The word file had corrupted itself who knows why.At the end it is not complicated to solve it. Take a look...
24 Oct 2013 by Sergey Alexandrovich Kryukov
To remove blank spaces from a string, use:rettext = rettext.Replace(" ", string.Empty);Please see: http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx[^].(Always use string.Empty instead of "", by a number of reasons.) It should work. If the string is not changes (are you 100%...
3 Dec 2013 by Maciej Los
Please, read my comment first.There are several resons why not to insert macros in normal template. The most important is security. Please, see this: Working with Microsoft Word Templates—The Foundation[^]As i mentioned, the simplest method is to replace normal.dot (using for example zip...
1 Jan 2014 by Jejaka Siber
hye, i have made this code which i have tried separately from my current web and it work perfectly but when i combine it with my web, i didn't get the output that was generated in the gridview. here is the code that i had used.protected void Wordbtn_Click(object sender, EventArgs e){ ...
31 Jan 2014 by CoderPanda
This[^] should help.[Please encourage participation by up-voting solutions or answers that work for you]
8 Feb 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Refer - Embedding word document in web form[^].Quote:If all the clients that are browsing the site are going to have Word installed and use Internet Explorer, you could embed it with an ActiveX object[^]. If these requirements are not met you might need to convert it to some more standard...
10 Feb 2014 by hari111r
Hi,Thanks for the solutions,To display the content with same format. I used this[^] to convert the word document to Html and simply displayed html page in Iframe.
13 Feb 2014 by hari111r
I am trying to convert word document to html in my asp.net applicaiton. it working fine in debug mode after i publish an hosted it is not working and i am getting the error "This command is not available because no document is open."Below is the code i am usingif...
13 Feb 2014 by Sergey Alexandrovich Kryukov
Microsoft does not recommend to use Office Interop in server settings:http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],http://support.microsoft.com/kb/257757/en-us[^].I would advise to use Open XML SDK...
17 Feb 2014 by hari111r
Hi, I am using below code to get the content from word document using Open xml SDK. I want to convert that to html with the formatting is there any option available to convert or we need to do it by parsing xml. string Path = Server.MapPath("Files\\Resume.docx");if...
25 Feb 2014 by Maciej Los
You should forget about DAO. Use ADO.net[^]!How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET[^]Accessing Microsoft Office Data from .NET Applications[^]Using ADO.NET to work with Excel files[^]USING ADO AND ADO.NET WITH EXCEL: Resources and...
9 May 2014 by Maciej Los
You did not specify what kind of issue do you have. Here is a complete tutorial: Customizing Context Menus in Office 2010[^]and Add-in that lists the IDs (idMSOs) of context menu controls is now available[^]
22 May 2014 by Maciej Los
Have a look here: Options.DefaultFilePath property[^] and set one of WdDefaultFilePath[^].Dim docPath As StringdocPath = Application.DefaultFilePath(wdDocumentsPath) & "\" & Format(Date, "yyyyMMdd") & ".docx"
29 Jun 2014 by _Sahar
I am using the Microsoft Ax Framer Control to view the word document in the Visual C# Form. After Hosting(Open) the Word Document in the Ax Framer Control. While Right Click on the Word Document, Ms word Context Menu is Appearing. I Want to Hide this Pop up Menu. I...
3 Jul 2014 by CHill60
Here is one technique...1. Download a free PDF creator e.g. http://www.pdfforge.org/pdfcreator[^] or http://www.cutepdf.com/[^] ... there are others2. If your free PDF creator doesn't hook to the Explorer context menu (right-click on a file to check) then set your default printer to...
5 Jul 2014 by ridoy
Check this, here font color is changed, you can change font style accordingly:C# search and replace font color in Word[^]Also get some idea from it:Bolding Text in Microsoft Word using .NET[^]
29 Jul 2014 by OriginalGriff
Assuming you mean "plus or minus" infront of a number for example:123.45+123.45-123.45Then it's simple:[+-]To allow either or nothing:[+-]?To allow neither followed by a floating point number:[+-]?\d+(\.\d+)