word-vba

Getting the selected item from the dropdown in a ribbon in Word 2007 using macro

别等时光非礼了梦想. 提交于 2019-12-06 13:08:20
问题 I see the following question which explains how to get the selected item from the dropdown:- http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/d1cf7b3e-68cf-4b82-b806-a3431acde3b6/ The above thread advises to have a hashtable of the items upfront, cache the selected id in the onAction() of the dropdown and use that selected id to find the item from the hashtable in the onAction() of the button. BUT, in my case, I populate the ribbon XML from the database. This ribbon XML obviously has

How to replace Numbers in Parentheses with some calculations in MS Word

孤街浪徒 提交于 2019-12-06 12:48:41
I have a problem to replace some serial number such as [30] [31] [32]... to [31] [32] [33]... in MS word when I insert a new references in the middle of article. I have not found a solution way in GUI so I try to use VBA to do that replacement. I find a similar problem in stack overflow: MS Word Macro to increment all numbers in word document However, this way is a bit inconvenient because it have to generate some replacement array in other place. Can I make that replacement with regex and some function in MS Word VBA like code below? Sub replaceWithregExp() Dim regExp As Object Dim regx, S$,

MSWord: Change font and font-size

纵然是瞬间 提交于 2019-12-06 12:19:20
问题 Why does this VBA code not work?: Sub AllToGeorgia12() Selection.Font.Size = 12 Selection.WholeStory Selection.Font.Name = "Georgia" End Sub This code is meant to turn all the text into Georgia font of size 12 Edit 1 : (This edit is my answer to supporters Froeschli and Foole ): I am sorry: I didn't notice right away that the code with the first two lines swapped (just as you have suggested) works fine on its own. However, it doesn't change the font and size when I attach it to another piece

Printing in Duplexpage a word document

半世苍凉 提交于 2019-12-06 09:33:29
问题 I am trying to automate the task of printing two copies at double page of ~30 Word document (*.doc). I want to send the program converted to .exe (I plan it just for Windows computers) using py2exe. I know that I can manually check the options but I will not be able to do so on the 20 or so computer where it will be used, as well as I cannot install in this computers new software (That's why I want to convert it into .exe ). I copied this solution to print, but I can't adapt it to do what I

Microsoft Word Mail Merge Data Source auto location

◇◆丶佛笑我妖孽 提交于 2019-12-06 09:29:34
I have written an Excel > Word Mail merge where the word document is the mail merge template. At the moment the location of the excel file (data source) has to be hard coded. I want to be able to move the files about the network, as long as they are in the same folder as each other, so it recognizes the data source is still the excel file. I currently have this piece of code which i thought would work. When the word document is opened at any point, it will re-create the data source by looking to the current directory of the file and looking for the file name PM MailMerge.xlsm. Then when it has

How to split a mail merge and save files with a merge field as the name

醉酒当歌 提交于 2019-12-06 09:19:19
问题 I have a bunch of mail merge templates setup, when I merge the documents I want to split the results into separate files each one with a name based on the merge field “FileNumber”. The code I have currently is: Sub splitter() ' Based on a macro by Doug Robbins to save each letter created by a mailmerge as a separate file. ' With help from http://www.productivitytalk.com/forums/topic/3927-visual-basic-question-for-merge-fields/ Dim i As Integer Dim Source As Document Dim Target As Document Dim

Word 2007 macros: is there an OnPrint event I can attach a macro to?

半城伤御伤魂 提交于 2019-12-06 08:59:21
问题 I'm looking to do a formatting check on word files before they get sent to the printer and it needs to be completely transparent to the user (no extra controls, just using the standard print options available through the UI). Is there an OnPrint or BeforePrint event, or something that can be used in that respect which I could attach a macro to, the same way I can with Open, Close, or Save? This feels like it should be simple... but those are famous last words. Thanks in advance, Rob 回答1: You

FileDialog in Word 2011 VBA

孤街浪徒 提交于 2019-12-06 07:52:21
问题 I'm hoping for a bit of a sanity check. I'm adapting a Word add-in (written in VBA for Word 2010) for Mac, specifically, at this point, Word 2011. I'm aware of many of the differences, but one that I haven't been able to find much documentation on is the apparent lack of FileDialog. The closest I've come to an answer is here: http://www.rondebruin.nl/mac.htm where the author uses Application.GetOpenFilename. That method doesn't seem to exist for Word, though (the focus of that site is Excel).

In VBA should code that modifies document be avoided in a class module

十年热恋 提交于 2019-12-06 06:45:21
问题 I am starting to use Classes in VBA and appreciate some of the fantastic information that is already available on SO. As far as I can tell, what seems to be lacking is an explanation of what the code in a class should or, as I suspect, should NOT do. For example: Lets say I have a document and wish to insert / modify a table. In this example I'd like to: check if the table exists if table does not exist: add the table at a specific location add information to the table (i.e. add rows) if

How to programmatically iterate through subscripts,superscripts and equations found in a Word document

允我心安 提交于 2019-12-06 06:20:24
问题 I have a few Word documents, each containing a few hundreds of pages of scientific data which includes: Chemical formulae (H2SO4 with all proper subscripts & superscripts) Scientific numbers (exponents formatted using superscripts) Lots of Mathematical Equations. Written using mathematical equation editor in Word. Problem is, storing this data in the form of Word is not efficient for us. So we want to store all this information in a Database (MySQL). We want to convert these formatting to