word-vba

Creating a dynamic list number in MS word using VBA

这一生的挚爱 提交于 2019-12-25 01:06:54
问题 I wonder how can I insert dynamic multilevel list numbers. The client request applying his Word 2010 template a "Point Headings" - similar to Point Pages behavior. Meaning: Assuming the following Heading formats: Heading 2 - 1.1 Heading 3 - 1.1.1 Heading 4 - 1.1.1.1 Heading 5 - 1.1.1.1.1 The purpose is to keep existent numbering and add in between numbered list. For example: Between two Heading 3 style headers 1.3.5 and 1.3.6 will come 1.3.5.A followed by 1.3.5.B and so on. obviously a

MSWord - ActiveX Fails to Invoke Objects

一曲冷凌霜 提交于 2019-12-24 23:20:26
问题 After a year using the MS Word 2013 VBA through ActiveX server calls under MS Win 8 Pro x64 , the following call ends in error: ActiveDocument.FormFields Yesterday I made a Windows Update including a Security Update for MSOffice 2013 64-bit . Today I uninstalled the update, and the problem now persists. 1. Matlab 2014b X=actxserver('Word.Application'); XD=X.Documents.Open('file.docx'); XD.FormFields No appropriate method, property, or field FormField for class Interface.Microsoft_Word_15.0

How to remove duplicate items in listbox

白昼怎懂夜的黑 提交于 2019-12-24 21:12:07
问题 I created this code to add found items enclosed with "[]" or "()" or "{}". If in my word document I have "ouch! [crying] That hurts! [crying] [laughing]" so the items enclosed with "[]" will be added to the listbox and there are 3 of it but the 2 are the same. I want to merge them. How would I do that? Sub cutsound() Dim arrs, arrs2, c2 As Variant, pcnt, x2, x3, intItems as Integer pcnt = ActiveDocument.Paragraphs.Count arrs = Array("[", "(", "{") arrs2 = Array("]", ")", "}") UserForm1.Show

Store multiple selections in Array and later do select all the selections in the Array

て烟熏妆下的殇ゞ 提交于 2019-12-24 19:53:04
问题 I am trying to find a word and save the selection in an array and then find again and then save the next selection in the array. And in the end try to select all the selections in the array. I am trying this but its with half knowledge. I am not able to get it. Can some one help. Sub Macro6() ' ' Macro6 Macro ' ' Selection.HomeKey Unit:=wdStory Dim selecttest(2) As Selection For I = 1 To 2 Selection.Find.ClearFormatting With Selection.Find .Text = "PQXY" .Replacement.Text = "" .Forward = True

How to copy excel range from a sheet and place it into a specific place it into a specific place in word using word vba

天大地大妈咪最大 提交于 2019-12-24 19:40:23
问题 I am trying to auto-populate a word document using the information in excel sheet. I want the user to be able to pick a desired excel file and want my macro to copy a specific range from different sheets for excel file and paste it into the specific area in word. So far I am able to open an excel file of my choice but not sure how the selection of range and pasting into specific location would work. Also, I am doing all this using word VBA and would also want to use word VBA to copy paste

Visual basic macro- changing the colour of specific text

烈酒焚心 提交于 2019-12-24 18:19:04
问题 Im very new to visual basic and macros. what i have been trying to do is create a macro that will look through the whole document and check to see if any of the font is red;if it is red then i want to change the red font to a white font. I know my code is wrong but can anyone tell me what i am doing wrong? Sub red() If Font.Color =wdColorRed Then Font.Color = -603914241 End Sub 回答1: You can use the following which is fairly quick (no looping required for each sheet). Sub Macro1() Application

VBA: How to loop through labels (not on a userform)?

帅比萌擦擦* 提交于 2019-12-24 16:24:24
问题 My Word document has many ActiveX labels. [Not textboxes: my original title was in error.] I'd like a macro to loop through them to perform an action on each of them (changing the captions), but I don't know how to identify them. If they were on a userform, I'd say: For each aLabel in UserForm1.Controls But that doesn't apply in my case. 回答1: Assuming it is textboxes you're working with, per the title but not the question, the document's Shapes collection may be what you're after: Sub

Word VBA: finding a set of words and inserting predefined comments

て烟熏妆下的殇ゞ 提交于 2019-12-24 13:24:03
问题 I need to automate the insertion of comments into a word document: searching for a predefined set of words (sometimes word strings, and all non case-sensitive) each to which I add a predefined comment. There are two word sets, with two goals: Wordset 1: identical comment for each located word Wordset 2: individual comments (I suggest new text based on the word identified) I have been semi-automating this with a code that IDs all identified words and highlights them, helping me through the

How to sort an array of strings containing numbers

五迷三道 提交于 2019-12-24 12:14:17
问题 I'm having some trouble correctly sorting an array numerically based on strings that contain numbers: So, the sort works for all strings up until I get into 2 digit numbers. For example, if the array contains "Issue 2:" "Issue 5:" and "Issue 3:" it correctly sorts the strings to be 2, 3, 5. Unfortunately, as soon as I get two digit numbers it no longer sorts correctly. So "Issue 10:" "Issue 8:" and "Issue 13:" will not sort. I'm fairly certain it has to do with the fact that I'm trying to

DocumentBeforeClose syntax

可紊 提交于 2019-12-24 11:14:33
问题 I really don't know the syntax of the DocumentBeforeClose event. Following this page, I should create a class module called 'EventClassModule' (see also this article). So I did. Then I copied this piece of code (from the example of the first link) into that (class)module: Public WithEvents appWord as Word.Application Private Sub appWord_DocumentBeforeClose _ (ByVal Doc As Document, _ Cancel As Boolean) Dim intResponse As Integer intResponse = MsgBox("Do you really " _ & "want to close the