Click here to Skip to main content
15,890,336 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 Updated

Microsoft Word 

29 Nov 2022 by H. Bala
I would like to create VBA script for fetching the details from online. If Input DOC files are less than six authors(Pl. find Voesenek L, Rijnders J, Peters A J M et al.) with et al., need the VBA Script should retrieve the remaining authors from...
29 Nov 2022 by CHill60
Your starting point is crossref.org - e.g. A non-technical introduction to our API - Crossref[^] Plenty of examples of using VBA to interact with an API - see vba api call - Google Search[^] When you have written some code do come back if you...
17 Oct 2022 by Sathya5995
scenario: update Table of content using OpenXML SDK 2.5 I will be adding contents in between the document using OpenXML/c#. TOC is already present in the document, I just want to update it programmatically. How to do it ? Thanks in advance :) What I have tried: ...
5 Sep 2021 by rachu223
Hello Everybody,We have created dynamic column chart using Microsoft word interop. Chart is generated successfully but sometimes it loads fresh chart or sometimes it takes data itself and generate chart with dummy data.Our code is as below. object bookmarkName =...
5 Sep 2021 by 依建 Lǐ Jiàn林 Lín
//Create an instance for word app Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application(); //Set animation status for word application winword.ShowAnimation =...
5 Aug 2021 by rajah rajah
Actually i want to read some particular content from word document using openxml. I've tried the below code for reading the document first. but i'm getting "file contains corrupted data".Is anyone came across openxml word document requirement. Kindly let me have a sample code. Thanks in...
5 Aug 2021 by Ashish Dubey 2021
Open XML Formats and file name extensions - Office Support[^] OpenXML will not work with doc format but with docx format. So if you are trying with doc format then first change it extension using below method ]public void...
23 Jun 2021 by Member 15260512
#clone your document import docx from copy import deepcopy doc1 = docx.Document('original_file.docx') copy_the_content = deepcopy(doc1) copy_the_content.save('new_file.docx')
4 Mar 2021 by William Damert
Console .NET application using Microsoft.Office.Interop.Word for keyword search
19 Dec 2020 by saleem_deek
Hi,I have a word template done with vba, and on a specific keyboard event I take changes done by user within document's BOOKMARKS to update them in DB.The problem is that some data has to be saved with their styling (Bold, Italic, Colors, Alignment), but when I try to copy the content of a...
19 Dec 2020 by Member 15025434
Thanms for finally writing about >[Solved] Too much unused style tags added to RTF text after being exported from word .dot to a .rtf - CodeProject
16 Dec 2020 by John Robert Connolly
I have word template files in .dot or .dotx format. I need to keep them in this format. What I am trying to do is when the document opens have vba code or something else that executes some logic and based on that logic opens the file normally or...
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 Nov 2020 by Gary Heath
I have been programming one way or another for over 40 years, but am quite a rookie on VB.net, so I still have trouble getting my head around things, hence my probably very simple question ... I have the following code that works, but my Form is...
24 Nov 2020 by Gary Heath
I have added a WindowsState line, as suggested by @Ralf_Meier, and it now works :-) Imports Microsoft.Office.Interop.Word Imports Microsoft.Office.Interop Public Class Form2 Private Sub Button1_Click(sender As Object, e As EventArgs)...
24 Nov 2020 by RickZeeland
Try TopLevel in combination with TopMost, Topmost is application-specific, not desktop. Form.TopLevel Property (System.Windows.Forms) | Microsoft Docs[^]
8 Nov 2020 by Pramod_Kumar1
Hi All, I have created multiple diffrent docx file using open xml and when i am merging all formatting of every docx reset and merged with first doc formatting. Please help me when my docx file will merge then formatting and design should be...
26 Oct 2020 by CyberSecII
I there any way to add a macro programmatically to a doc(Word) document and then save it? What I have tried: Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application(); ...
16 Oct 2020 by Richard MacCutchan
https://www.codeproject.com/Questions/5269728/Using-VB-NET-to-add-automatically-macro-code-into[^]
1 Oct 2020 by lauuster
I am new to Python. I tried writing a code to extract details from specific Word's table cell and export as Excel. However, I seems can't to extract the correct details from word's table to excel sheet. I am able to extract details from row 1-3,...
1 Oct 2020 by Richard MacCutchan
# Get the 5th row of data for l in range ( 1 , 7 , 6 ) : cell = tb . cell ( 4 , j ) You are using the index named l for your range, but trying to use j to refer to the data item. The index j is never declared anywhere.
27 Sep 2020 by Member 14949846
Hi there, Utilizing Excel or Python, I am trying to determine the # of word documents in which a single word occurs. For example, let's say I have 100 word documents. Of these documents, I would like to find out how many contain the word "Excel"...
27 Sep 2020 by CPallini
For each document, search for the requested word and exit reporting success as soon as you find it. That's all. The trickiest part is how-to-perform-such-search. For instance, if you stick to Python and your targets are Word documents, then...
27 Sep 2020 by OriginalGriff
That's going to be complicated, as you will need to be able to read Word documents, extract the text, check for an instance of your word, and then open the next and repeat the process. If you have code to read a file and count words, then all...
30 Jul 2020 by Darryl Bryk
My software copies graphs into a Word document, and the document is based on various templates that users have made, therefore the usable page height varies, depending on header/footer and margins. I'm trying to optimize the graph height and...
30 Jul 2020 by Maciej Los
Darryl Bryk wrote: Code to copy a graph: using (MemoryStream mem = new MemoryStream()) { cht.SaveImage(mem, ChartImageFormat.Bmp); using (Bitmap bmp = new Bitmap(mem)) { Clipboard.SetImage(bmp); if (Clipboard.ContainsImage()) par.Range.Paste();...
21 Jul 2020 by Dilan Shaminda
Hi, I am using using Microsoft.Office.Interop.Word; assembly in order to access the word files and do some stuff. I want to know is there any way that I can get the character position where the cursor is currently in. What I have tried: Below is the code I use Object wordObject = null; ...
21 Jul 2020 by Member 12734776
Hello you use this for get cursor position range First must active document word_application.Selection.Range
17 Jul 2020 by Trekkie_RIF
Not what you ask for but - I can only find how to set the color using RGB. I suppose you can find somewhere on the internet to manually convert your hex color: Hex to RGB Color Converter[^] Or, you can convert hex to RGB programmatically: Excel...
1 Apr 2020 by mystiquesbs
So what i'd like to do is link a database to a GUI that people can easily add information into the database. The next step is to get that information and populate it into Microsoft office documents such as word, excel, powerpoint etc. And create...
1 Apr 2020 by Garth J Lancaster
I already have time on my hands thanks to covid-19 & Business Hibernation ..so I'm studying/refreshing 'all sorts of things'. I think it would be all too tempting to throw things at you like 'do it with C# & Winforms, or c++ & MFC, or 'any other...
7 Mar 2020 by JOHNNYDEMICHAEL
Writing a Microsoft Word letter . . .using Word = Microsoft.Office.Interop.Word;The following code will BOLD the sentence. How do you specify a range that includes only one word . . . say you want to bold only the word electronically in the sentence or paragraph . . . how would you...
7 Mar 2020 by Chris M. Darby
Here's some sample C# code with a few demonstrations of Interop Word usage, including one approach to selectively setting individual words to a bold font. The trick is to collapse the range in between every change or deviation with Word styles...
6 Feb 2020 by Fred Andres
Thanks for your help Maciej. With your information I was able to come up with the following solution which is lightening fast: public void find_and_replace_text(string curr_text, string new_text) { Word.Find findObject; var missing = Type.Missing; ...
6 Feb 2020 by Fred Andres
I wrote the following code to find the location of a text string in a word document. It works but it is glacially slow. How do I speed it up? public int find_text(string some_text) { int point0; int location; int text_length; ...
5 Feb 2020 by Maciej Los
As you mentioned, you have to use Find method. See: Find and replace text in documents programmatically - Visual Studio | Microsoft Docs[^] How to: Programmatically loop through found items in documents - Visual Studio | Microsoft Docs[^] How to: Programmatically restore selections after...
8 Nov 2019 by amrinde
you should use save as oDoc.SaveAs("MyFile.doc", ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
5 Nov 2019 by evan1138
I'd like to know if, and then how, to embed HTML and javascript into a Word 2010 document so as to for instance change a font depending on contents of an external file. The HTML and javascript of course will not show in the word document, thll just be lurking and will run when the document is...
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
20 Oct 2019 by RickZeeland
See the section "To add and remove controls on the active document" here: Add controls to document at run time in VSTO Add-in - Visual Studio | Microsoft Docs[^] Detecting the Delete key from the KeyPress event will not work, but you can use KeyDown instead. Here is an example: Keypress Event...
19 Oct 2019 by Member 14625136
Hello, how can I make a Textbox deletable by the User at runtime, without using the design mode? The User should be able to select the Textbox and remove it with the "DELETE" Key. I use the C# VSTO Word Add-in in Visual Studio. I would be happy for any response! What I have tried: I searched...
30 Sep 2019 by jankichavda
I have a list of data to insert in Word document.I am using Microsoft Word Object Library dll for data insert in Word document.my data look like first column is image and other column is name,address etc..One record should be display in only one page in created document.when I insert data in...
30 Sep 2019 by Member 12485855
Yes. Some problems... May be create table and fill cells?
3 Sep 2019 by Patrice T
Quote: Run-time error 4605 this method or property is not available because no text is selected If you read carefully the error message, it tells you why there is an error. Chances are that it also tells you the line where error occurs, chances are that it also propose to open the debugger. ...
3 Sep 2019 by Shankrayya R
I have master word document which contains sample payslips pagewise and i want split each page and save it as separate word document based on employee code mentioned in the particular word document page. I have written VBA code for this but this is not working , kindly help me in this I am...
21 Aug 2019 by Avoird
Hi, For our document printing needs i am writing a new service application (in c#) that needs to print documents in word templates. The concept is based on an old c++ based application we had in the late nineties. What the service basically does is, it open a word document with a macro-function...
18 Aug 2019 by Maciej Los
Based on that piece of code you've provided i can not tell you what's wrong with it, but... Quote: It is important to note that the Find criteria are cumulative, which means that criteria are added to previous search criteria. Clear formatting from previous searches by using the...
18 Aug 2019 by Arnold Samuel
I need to tag string in bold, Underlined, Italics. Example : Input : This strings are not in bold but this string are in bold.This is italics. Ouput: Quote: This strings are [u]not in bold[/u] but [b]this string are in bold[/b].[i]This is italics[/i] individual words are getting tagged...
12 Aug 2019 by kedar001
i'm Opening Word File from my Application in HTTP Path i.e. http:\\Server\SiteName\TempFiles\filename.docx Word File Showing message as "READ ONLY : This Document is Lock for Editing by another user" because of this my macro didn't work Protection = ActiveDocument.ProtectionType If...
11 Aug 2019 by OriginalGriff
Read the message: READ ONLY : This Document is Lock for Editing by another user That means just what it says: the file is in use, and until it is no longer being used you can't access it. Probably, you app is not closing iot's files properly, and the file remains in use from a "previous...
31 Jul 2019 by Gerry Schmitz
One creates (longer) "borders" by only drawing one side of a set of contiguous cells; unless one uses a "border" CONTROL that can host "child" controls / cells. e.g. 2 x 2 cells would require "8" side "drawings" for a border. (Thickness(1,0,0,0); etc.) You can build WYSIWYG data entry forms up...
31 Jul 2019 by amsga
Hi, I am currently using Interop.Word to draw tables for a document. I am looking to draw only the outside border for a set of cells (e.g. R1C1 to R2C3) I roughly know how to draw a full outside border around one cell. I am hoping that I can just call something to draw the border around the...
22 Jul 2019 by Richard MacCutchan
Try Document.SaveAs2 method (Word) | Microsoft Docs[^]
22 Jul 2019 by Bip baaap
How do i set a password convered file word to pdf then protect password. i tried some codes but did'nt work , this is made from vb.net filepath = "C:\Users\" & Environ("Username") & "\Desktop\WindowsApplication2\Payslips\Payslip " & item.SubItems.Item(1).Text & " " &...
15 Jul 2019 by dirtyshooter
Sub InsertFooter() Dim rng As Range With ActiveDocument.Sections(1) With .Headers(wdHeaderFooterPrimary) Set rng = .Range.Duplicate rng.Collapse wdCollapseEnd rng.InsertBefore vbTab & "Page { PAGE } of { = { NUMPAGES } -1 }" ...
15 Jul 2019 by dirtyshooter
I have a word application. The header shows pagination in the style (1 of 9). How do I decrease the total number of pages programatically. I tried to record macro, but that doesn't work as expected. Page {PAGE} of {={NUMPAGES}-1} I have to achieve this through vba code. What I have tried: ...
11 Jul 2019 by Maciej Los
You've gt 2 ways to achieve that: method #1 PageNumbers.Add method (Word) | Microsoft Docs[^] method #2 Fields.Add method (Word) | Microsoft Docs[^] Sub AddPageNumbering() Dim doc As Document Dim header As Range Set doc = ActiveDocument Set header =...
20 May 2019 by Member 14393657
Hi, I am a teacher, and I need to edit a question bank document. The answers follow immediately after questions as following: Question 1. Choose the best description of "X" a. [description 1] b. [description 2] c. [description 3] d. [description 4] Answer c Question 2. Choose........... ...
20 May 2019 by RickZeeland
Something like this: Sub DeleteAnswers() Dim oRng As Word.Range Set oRng = ActiveDocument.Range With oRng.Find .Text = "Answer" While .Execute With oRng.Paragraphs(1).Range If .Characters(1) = "Answer" Then .Delete End With Wend End With End Sub
20 May 2019 by Gerry Schmitz
The "Answer" consists of TWO "words". When Text = "Answer", delete current word AND "next" word. Then continue with next question.
15 Apr 2019 by Aaron Queenan
It's a bit late to help the original poster, but in case anyone else finds this article, here's an explanation of the problem. Although other content controls support standard (MSXML3) XPath syntax, the repeating section content control only appears to support very simple XPath syntax, allowing...
15 Apr 2019 by Beunens Filip
Hello,I have a MS Word (2016) temaplate and mapped a XML file to the content controls in a table, also using a repeating control. This Works fine but now I would like to filter the mapped XML data in the repeating control.Say I have this XML File
11 Apr 2019 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.
6 Apr 2019 by Member 12994860
Change the Font Color of all Equations in a Word Document
6 Mar 2019 by CHill60
The default extension for Word is .doc or .docx. That is why...Word has finished it off for you. But, if you were to run exactly the same code in Excel VBA it would look for .xls or .xlsx files. It's always best to be explicit. For example.. what if you have both a test.doc and a...
6 Mar 2019 by dirtyshooter
Documents.Open FileName:="C:\test", ReadOnly:=False OR Documents.Open FileName:="C:\test.doc", ReadOnly:=False What I have tried: Both the code works. Why do I have to give extension then?
5 Mar 2019 by gani7787
Hi, I have the hyperlink in table. when the user click on the link it suppose to open the document. The challenge of the task is, when one person open the document, then the other person should not open the document. It should say some alert saying "This person opening the document,pls....
4 Mar 2019 by OriginalGriff
The hyperlink can't go direct to the file: it has to go to a webpage (possibly with a identifying query string) which checks the DB and either serves the file or displays a message. Your problem is "closing the file" - unless the remote client is forced to tell you when he closes it, there is...
3 Mar 2019 by Member 12045288
I have to convert .doc file byte array to html string using C# without using interop dll and Ms office installed is there any way to do that? What I have tried: I have gone multiple libraries but all are paid and I didn't find any library which does the work in memory stream without saving...
3 Mar 2019 by F-ES Sitecore
You can try DocX. Not sure if it does .doc files or only .docx ones. NuGet Gallery | DocX 1.3.0[^]
3 Mar 2019 by Mehdi Gholam
Read this : c# - Convert from Word document to HTML - Stack Overflow[^]
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...
3 Feb 2019 by CodeMine
i have a table in microsoft word as given below name english hindi odia telugu total average grade aa 5 5 78 34 122 30.5 ? how can i find the grade according to following conditions using "if" only If total mark > 250 the grade “A” else if total mark > 200 grade “B” else...
21 Jan 2019 by Member 13278902
"Download COMMTB32.DLL and copy at same Directory as VB6.exe" Worked for me
21 Jan 2019 by Member 11438562
We have very strange error here for which we could not find any solution. I hope VB6 ,word expert could help us in this. We have our code in VB6. There is a functionality in the code in which we send the word documents to client/users through the code. Word documnets have bookmarks in them....
13 Jan 2019 by Maciej Los
Please, read this: How to: Programmatically add headers and footers to documents - Visual Studio | Microsoft Docs[^]
13 Jan 2019 by Member 10242311
Hi Friends, I have an update to insert the page header in Word document. I have tried below-mentioned code, but its shows the compile time error. Any one polease help me. What I have tried: string appPath = Path.Combine(Environment.SpecialFolder.ApplicationData.ToString(), @"Microsoft\Document...
21 Dec 2018 by RickZeeland
Here is a (lengthy) discussion about the same problem, which seems to be solved: [RESOLVED] How to copy Auto-Numbering and Pure-Text from RichTextBox or MS Word ?-VBForums[^]
21 Dec 2018 by Marcin Bednarek
I have in Microsoft Word 5 lines od text with auto numbering. All lines have it's own formatting like bold, italic, etc. 1. Line 1 2. Line 2 3. Line 3 4. Line 4 5. Line 5 When I copy to clipboard selected lines 2-4 and paste it into TextBox control in VB.NET Windows Form Application I get...
14 Nov 2018 by Vincent Maverick Durano
Developing a system like "Google Docs" requires alot of effort, time, expertise and research. I'm not even sure if there's a similar component that does the same job. Since you want an app that acts like Google docs, you would still need to use Google Docs and integrate that into your app to...
14 Nov 2018 by mabbaszadegan
Hi all! I want create an application in ASP.Net C# that can upload a office word (.doc or .docx) and show it on editor and user can edit and save it. (similar google doc) I don't want use usual text editor such as: ckEditor or devexpress or etc. Please suggest me a solution or help me for more...
3 Sep 2018 by Member 11643680
I wrote a Windows Forms program using C#. It contains textboxes and a data-grid. I want to export the data into a Word file to use the template. I added the library of Microsoft Word into my code. Also I created textboxes "shapes" inside the Word file and putted inside them text to be find...
3 Sep 2018 by Graeme_Grant
The easiest way that I have found to figure out the code is to use the in-built Macro Recorder as it will write the code for you! ;) Here is a video that should help: Intro to Word Macros - Tutorial on How to Edit a Word Macro - YouTube[^]
16 Aug 2018 by Gerry Schmitz
Didn't search very hard: GitHub - bjherger/ResumeParser: A framework to parse resumes, extract contact & other information, and check for required terms[^] How To Create Your Own Job Board Using WordPress | Elegant Themes Blog[^]
16 Aug 2018 by SANDIP A PATIL
Dear All, I Have one project like Naukari and Monster, within Project i need to upload the Resume, after uploading resume file it will automatically read the content from File and Separate the Field like Name, Contact, Email, Skills and store into DB . Please give me the Suzzetions Thanks, ...
15 Aug 2018 by Member 13923913
I have a word file: paragraph1 paragraph2 paragraph3 paragraph4 paragraph5 I want to Join all lines of text into one: paragraph1. paragraph2.paragraph3.paragraph4.paragraph5 Help me. Thanks all!!! What I have tried: Word.Range rang = Globals.ThisAddIn.Application.ActiveDocument.Range();...
30 Jul 2018 by Patrice T
Quote: The purpose for this post is that nobody can edit/delete contents of ms word file Then do not provide as a Word file ! Provide it as a pdf. Quote: nobody can create a copy of this ms word file. As soon as it is displayed on screen, it is impossible. The user just have to use the Capture...
30 Jul 2018 by Jochen Arndt
There are no options to disable general menu items in Word as far as I know. If you want to disallow editing, protect your document with a password: Select "Save As - Tools - General Options" and set a "Password to modify" but not a "Password to open". If you need further restrictions like...
30 Jul 2018 by yash1507
Hi, I want to open a word document using vb.net, need to disable options like FILE, HOME, INSERT, DESIGN, PAGE LAYOUT etc. Kindly suggest vb.net code to disable top menu options in ms word/winword file. Thanks & Regards, Saurav Sinha What I have tried: I didn't get any useful links.
18 Jul 2018 by Member 13917739
myRange = myDoc.documents.Add(new ImAGE);
12 Jul 2018 by Michael Breeden
I'm converting an ASP Classic project to .Net, The original application uses something along the line of: this.oWord=GetObject("","Word.Application"); to display an instance of Word in an iframe using an ActiveX object. The web page contains controls to do fairly sophisticated control of the...
22 Jun 2018 by Patrice T
Quote: Trying to read MS word file An msword file is not plain text, that is the reason why one use library to read/change/save such a file. The 'PK' you see at beginning of file is the signature of a zip file. The word file is a zip archive and the 'PK' signature is beginning tag of each...
22 Jun 2018 by bhupi chauhan
Hi I am trying to read ms word file from server path by following code : string wordHTML = System.IO.File.ReadAllText(path); but the content is showing like this.Please suggest to read word file content as it is. PK!�t+d�7[Content_Types].xml...