ms-word

How to raise an event on MS word Keypress

纵饮孤独 提交于 2019-12-29 07:47:28
问题 I am developing a MS-Word addon in which my code has to get access to the letters the user is entering through the keyboard. private void ThisDocument_Startup(object sender, System.EventArgs e) { this.SelectionChange += new SelectionEventHandler(ThisDocument_SelectionChange); } void ThisDocument_SelectionChange(object sender, SelectionEventArgs e) { MessageBox.Show(e.Selection.Text); } I think the SelectionChange event can give me the text but the event is not raised at keypress, Is there any

How to run a macro in Word before save?

痴心易碎 提交于 2019-12-29 07:07:06
问题 How to make Microsoft Word to run a VBA macro every time before any document is saved? Could it be done without adding macros into the document itself? 回答1: You can subscribe to application events in Document_Open by using WithEvents variable and conventional method names ( VariableName_EventName ). Works in templates as well. You can put this code into ThisDocument object, or make a separate class module as described here. Private WithEvents App As Word.Application Private Sub Document_Open(

Printing using Word Interop with Print Dialog

妖精的绣舞 提交于 2019-12-29 06:53:01
问题 I'm trying to print a word doc from my C# code. I used the 12.0.0.0 Word Interop and what i'm trying to do is to get a Print Dialogue pop up before the document prints. I'm not 100% sure of the syntax of all of this as I can't get my code to work :( Any ideas? Thanks in advance! 回答1: It should be something along the lines of: object nullobj = Missing.Value; doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref

Printing using Word Interop with Print Dialog

╄→尐↘猪︶ㄣ 提交于 2019-12-29 06:52:09
问题 I'm trying to print a word doc from my C# code. I used the 12.0.0.0 Word Interop and what i'm trying to do is to get a Print Dialogue pop up before the document prints. I'm not 100% sure of the syntax of all of this as I can't get my code to work :( Any ideas? Thanks in advance! 回答1: It should be something along the lines of: object nullobj = Missing.Value; doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref

Word VSTO swallows exceptions at runtime without debugging?

一个人想着一个人 提交于 2019-12-29 05:45:15
问题 Place this code somewhere in a Word document level VSTO solution outside of ThisDocument_Startup (create a ribbon button, with a click event): int zero = 0; int divideByZero = 10 / zero; Start without debugging (Ctrl + F5), Result: Exception is swallowed, the rest of the code fails silently. The exception will be visible if placed in ThisDocument_Startup, but it appears nowhere else. Microsoft's VSTO forums and the MSDN documentation seem to feel Try...Catch should be used - which is not a

Serialize current ActiveDocument from office 2007 add-in

女生的网名这么多〃 提交于 2019-12-29 01:17:33
问题 Im creating a VSTO Office 2007 add-in. I need to be enable or find a solution where I can save to a webservice with a byte[] instead of hard drive. So, I open the document by going to a website and clicking on a url, that click send me a Word Document, and I select Open using MS Word 2007. The document open, and if I check the data I have: ActiveDocument.Fullname = http://[servername or ip]/[some iis folder]/file.asp?id=353&type=doc` so I think this is all in memory since I dont have the

Set custom document properties with Word interop

我只是一个虾纸丫 提交于 2019-12-28 18:05:25
问题 I want to set some custom document properties of a word document I'm creating in my C# code. To do this, I followed this MSDN article and came up with this code: using Word = Microsoft.Office.Interop.Word; // Version 12.0.0.0 word = new Word.Application(); word.Visible = false; Word._Document doc = word.Documents.Add(ref missing, ref missing, ref missing, ref missing); logger.Info("Setting document properties"); Core.DocumentProperties properties = (Core.DocumentProperties)doc

I have a VSTO application as an add-in to MS Word and I want to set keyboard shortcuts to the ribbon buttons

血红的双手。 提交于 2019-12-28 06:34:13
问题 When I developed this app (in C# Visual Studio 2008) I asked the same question (actually managed to find an answer on the MS forum, for which I deserve a prize of some sort). The answer from MS was that the only way to set keyboard shortcuts to your own methods is to write a macro which invokes the method (via COM. obviously) and set the shortcut to invoke that macro. This is really not the answer I want to hear. VSTO makes it possible to build a really nice application with very good use of

C#: Searching a text in Word and getting the range of the result

独自空忆成欢 提交于 2019-12-28 06:21:32
问题 I can find a text in a Word file via: Word.Range range = wordApp.ActiveDocument.Content; Word.Find find = range.Find; find.Text = "xxx"; find.ClearFormatting(); find.Execute(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); This tells me if the text is found. But I need the range of the found text-piece. 回答1: Have you tried this: range.Find.Execute(

C#: Searching a text in Word and getting the range of the result

北城余情 提交于 2019-12-28 06:21:05
问题 I can find a text in a Word file via: Word.Range range = wordApp.ActiveDocument.Content; Word.Find find = range.Find; find.Text = "xxx"; find.ClearFormatting(); find.Execute(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); This tells me if the text is found. But I need the range of the found text-piece. 回答1: Have you tried this: range.Find.Execute(