word-vba

VBA - How to add a collection to a collection of collections

会有一股神秘感。 提交于 2020-01-02 01:17:12
问题 I am trying to create code to represent a form document using VBA in Word 2007. I have created classes to represent Section, QuestionSet and Question. So I have 15 Sections. I have created a function to create each 'Section' Object add it to the 'Sections' Collection then destroy the object, the result being that the objects remain persistent in the collection (or something). Is it possible to use the same method to add collections to collections or would I have to define each collection

Word VBA: Get Range between Consecutive Headings

妖精的绣舞 提交于 2020-01-01 18:16:33
问题 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

select a range of text from one Word document and copy into another Word document

房东的猫 提交于 2020-01-01 09:40:22
问题 I'm trying to use VBA to extract sentences in one Word document and put it into another Word document. So for example, if we need to find the title of the organization, we follow the algorithm: Search for "Title" Do (Take) each character after "Title" and (stop) until "Address" 回答1: The following works but there may be a more efficient way of doing this: Sub FindIt() Dim blnFound As Boolean Dim rng1 As Range Dim rng2 As Range Dim rngFound As Range Dim strTheText As String Application

select a range of text from one Word document and copy into another Word document

旧时模样 提交于 2020-01-01 09:40:18
问题 I'm trying to use VBA to extract sentences in one Word document and put it into another Word document. So for example, if we need to find the title of the organization, we follow the algorithm: Search for "Title" Do (Take) each character after "Title" and (stop) until "Address" 回答1: The following works but there may be a more efficient way of doing this: Sub FindIt() Dim blnFound As Boolean Dim rng1 As Range Dim rng2 As Range Dim rngFound As Range Dim strTheText As String Application

VBA Macro to search a text string and replace with hyperlink works only with English text, but not Arabic

五迷三道 提交于 2019-12-31 06:44:14
问题 I have Arabic texts in Microsoft Word that I need to introduce hpyerlinks to some of its words. The reply to this question here works for me, but only for English words. When I replace the word "google" with any Arabic string (Whether one word or multiple words), the macro does not work. I can display the Arabic characters correctly in VBA, using the answer to this question here, so there are no problems displaying the text in the macro. Can you please help me understanding what code

VBA Macro to search a text string and replace with hyperlink works only with English text, but not Arabic

ぃ、小莉子 提交于 2019-12-31 06:43:26
问题 I have Arabic texts in Microsoft Word that I need to introduce hpyerlinks to some of its words. The reply to this question here works for me, but only for English words. When I replace the word "google" with any Arabic string (Whether one word or multiple words), the macro does not work. I can display the Arabic characters correctly in VBA, using the answer to this question here, so there are no problems displaying the text in the macro. Can you please help me understanding what code

Add Shape at the end of the document

主宰稳场 提交于 2019-12-31 04:05:19
问题 I'm trying to add a shape specifically a textbox. I need to add it after all the contents I added through vba. I can't seem to figure how to do it since adding the shape needs the exact measurement of the Left and Top parameters. Dim shpActual Dim pos, PtsToInches set shpActual = Selection.Shapes.AddTextbox(msoTextOrientationHorizontal, 92, PtsToInches, 437.4, 69) pos = Selection.Range.Informatio(wdVerticalPositionRelativeToPage) PtsToInches = pos / 72 回答1: You can use the

VBA MS-Word Work with mutiple discontinuous selection?

两盒软妹~` 提交于 2019-12-31 02:46:06
问题 I'm trying to do something with a multiple selection. I wanna add some text before every selected paragraph but, when I select multiple discontinuous paragraphs, if I do Selection.Paragraphs.Count I always get "1". How could I work with all paragraphs apart? Example: Paragraph1(Selected first) Paragraph2 Paragraph3(Selected second) What I got when I try to add some text at the beginning of these paragraphs: Paragraph1 Paragraph2 TEXTParagraph3 What I really want to obtain: TEXTParagraph1

Calculation fields not working with dates

最后都变了- 提交于 2019-12-30 11:34:17
问题 I have seen quite a lot of examples looking for a solution, so I'm pretty certain that this possible. I have Custom Document Properties (properly defined as date) containing dates , and I want to make operations on them : {={ DOCPROPERTY DateFieldTest }+1 \@"d MMMM YYYY"} 'toggle DOCPROPERTY Field {=07/04/2016+1 \@"d MMMM YYYY"} 'toggle calculation field 1 I have also tried : {=DATE(YEAR({ DOCPROPERTY DateFieldTest }),MONTH({ DOCPROPERTY DateFieldTest }),DAY({ DOCPROPERTY DateFieldTest })+1)

ActiveX textbox value

寵の児 提交于 2019-12-30 09:52:57
问题 How do I get the value of a textbox in Word? I know in excel this is the right syntax: ActiveSheet.Shapes(x).Name . I thought in word this would be the right syntax ActiveDocument.Shapes(x).Name , but this doesn't seems to work. With this piece of code I also couldn't find a textbox: For i = 1 To ActiveDocument.Shapes.Count MsgBox ActiveDocument.Shapes(i).Name Next i 回答1: To get the value of a standard textbox , use this: ActiveDocument.Shapes(1).TextFrame.TextRange.Text To get the value of