Macro to update all fields in a word document

For years, the standard I’ve used for updating all fields (with the exception of TOC, etc. which are handled separately) in a document is the one the Word MVPs use and recommend, which I’ll copy here. It comes from Greg Maxey’s site: http://gregmaxey.mvps.org/word_tip_pages/word_fields.html. One thing it does that I don’t see in your version is … Read more

html to .doc converter in Python?

You could use win32com from the pywin32 python extensions for windows, to let MS Word convert it for you. A simple example: import win32com.client word = win32com.client.Dispatch(‘Word.Application’) doc = word.Documents.Add(‘example.html’) doc.SaveAs(‘example.doc’, FileFormat=0) doc.Close() word.Quit()

Get PID from MS-Word ApplicationClass?

Here is how to do it. //Set the AppId string AppId = “”+DateTime.Now.Ticks(); //A random title //Create an identity for the app this.oWordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); this.oWordApp.Application.Caption = AppId; this.oWordApp.Application.Visible = true; while (GetProcessIdByWindowTitle(AppId) == Int32.MaxValue) //Loop till u get { Thread.Sleep(5); } ///Get the pid by for word application this.WordPid = GetProcessIdByWindowTitle(AppId); ///You canh … Read more

Macro to export MS Word tables to Excel sheets

Answer taken from: http://www.mrexcel.com/forum/showthread.php?t=36875 Here is some code that reads a table from Word into the active worksheet of Excel. It prompts you for the word document as well as the table number if Word contains more than one table. Sub ImportWordTable() Dim wdDoc As Object Dim wdFileName As Variant Dim TableNo As Integer ‘table … Read more

Speed up multiple replacement

For a start don’t specify all those properties over and over again. Unless you change them they don’t change. With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .MatchFuzzy = False For loop … Read more

Use Office Interop on ASP.net MVC6 website

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment. If you are building a solution that runs in a server-side … Read more

HTML generated Microsoft Word document with header, footer and watermark

This is some example, hope it helps others that are trying to generate ms word .doc file with HTML. <html xmlns:v=”urn:schemas-microsoft-com:vml” xmlns:o=”urn:schemas-microsoft-com:office:office” xmlns:w=”urn:schemas-microsoft-com:office:word” xmlns:m=”http://schemas.microsoft.com/office/2004/12/omml” xmlns=”http://www.w3.org/TR/REC-html40″> <head><meta http-equiv=Content-Type content=”text/html; charset=utf-8″><title></title> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <style> @page { mso-page-orientation: landscape; size:29.7cm 21cm; margin:1cm 1cm 1cm 1cm; } @page Section1 { mso-header-margin:.5in; … Read more