word-vba

Printing in Duplexpage a word document

给你一囗甜甜゛ 提交于 2019-12-04 17:11:31
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 want: from win32com import client import time word = client.Dispatch("Word.Application") filename=input

Word VBA: Get Range between Consecutive Headings

旧巷老猫 提交于 2019-12-04 16:28:21
I looked up some examples, but I cannot quite understand how the Range object works. I am trying to loop through each of my headings (of level 4) and have a nested loop that looks through all the tables in between the headings. I cannot figure out how to set that specific range, so any help will be greatly appreciated. Dim myHeadings As Variant myHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHeading) For iCount = LBound(myHeadings) To UBound(myHeadings) level = getLevel(CStr(myHeadings(iCount))) If level = 4 Then 'This is where I want to set a range between myHeadings(iCount) to

FileDialog in Word 2011 VBA

给你一囗甜甜゛ 提交于 2019-12-04 14:55:23
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). Does anyone know how to use the file and folder picker dialogs that FileDialog makes available? I'm

Is it possible to access a parent property from a child that is in a collection?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 14:50:28
问题 I've researched as much as I can and never found a definitive answer on this for VBA. This older StackOverflow post has almost everything, but not quite. VBA Classes - How to have a class hold additional classes Bottom line - I have a class CClock, which is parent to a Collection of CContacts, which is parent to a CContact. Is there any way to get at a property of the CClock class from a CContact. So something like Debug.Print , clsContact.Parent.Parent.Lawyer in the code below? I've tried

VBA code stops whenever I open a document

不问归期 提交于 2019-12-04 12:53:16
First of all sorry for posting this, I know it's probably duplicated from this post, I tried to post it as an edit but it got rejected and I can't comment because I don't have 50 reputation, also this is not a proper answer. Hope this helps to get a better understanding of the problem and more attention. I work in a company that uses VBA and we've been using Documents.Open for a long time and it never gave me any problems, until now. The problem seems rather random, as not many clients have this, but it's turning more consistent now mainly with Office 365. Maybe it's due to an actualization?

Programmatically set DLL search path in VBA macro

◇◆丶佛笑我妖孽 提交于 2019-12-04 11:04:35
问题 The problem I have a word template which uses VBA's Declare statement to link to a dll, whose path can be determined within the VBA macro I want to delploy this to the users %APPDATA%\Microsoft\Word\STARTUP directory I DON'T want to permanently change the user's PATH environment variable (temporarily would be OK, but this doesn't seem to work as they don't get refreshed until application restart) Attempted solution I tried dynamically adding the code with the Declare statements using

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

心已入冬 提交于 2019-12-04 09:24:17
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 table does exist add / delete information to /from the table sort the table according to some criteria With

How do I retrieve the name of a shape in MS Word?

只谈情不闲聊 提交于 2019-12-04 07:38:06
In Excel we have the "Name Box" in the upper-left side, but I could not find a way to retrieve the name of a shape in Word. How do I do that? There are two types of shapes in MS Word- InlineShapes and Shapes . It's quite easy to check name of shape object with some VBA code: select shape press Alt+F11 to open VBA Editor in Immediate window execute this code: ? Selection.ShapeRange.Name as a result you get name of the shape. InlineShape doesn't have name property therefore you can't check it's name until you promote your InlineShape to Shape type object. Microsoft Word 2010 onwards From

Regex Word Macro that finds two words within a range of each other and then italicizes those words?

*爱你&永不变心* 提交于 2019-12-04 05:57:57
So, I'm just beginning to understand Regular Expressions and I've found the learning curve fairly steep. However, stackoverflow has been immensely helpful in the process of my experimenting. There is a particular word macro that I would like to write but I have not figured out a way to do it. I would like to be able to find two words within 10 or so words of each other in a document and then italicize those words, if the words are more than 10 words apart or are in a different order I would like the macro not to italicize those words. I have been using the following regular expression:

Looping through the parts of a non-contiguous selection in MS *Word* VBA

你说的曾经没有我的故事 提交于 2019-12-04 05:28:59
问题 I have a macro in MS Word 2013 VBA ( not Excel) that toggles the selected text's highlight color. Code looks like this: If Selection.Range.HighlightColorIndex = WhtColor Then Selection.Range.HighlightColorIndex = wdNoHighlight Else Selection.Range.HighlightColorIndex = WhtColor That works great for continuous/contiguous selections. But, if I select, say, 4 non-contiguous rows in a Word table (say, rows 5, 12, 15, and 19), the macro highlights only the last row selected. How do I get the