word-vba

Using VBA to parse text in an MS Word document

喜你入骨 提交于 2019-11-29 22:10:57
问题 I was hoping someone could help with a MS Word Macro. Basically, I have a MS Word document which lists out several text files and specific pages of interest in each file. The file format is similar to: textdocument1.txt P. 6, 12 - issue1 textdocument2.txt P. 5 - issue1 P. 13, 17 - issue3 textdocument3.txt P. 10 I want to read each line into my Macro as a string. Then traverse through it to identify the file name. With the file name, I can then open the file, go to the page number, and copy

Return multiple values from a function, sub or type?

▼魔方 西西 提交于 2019-11-29 20:26:24
So I was wondering, how can I return multiple values from a function, sub or type in VBA? I've got this main sub which is supposed to collect data from several functions, but a function can only return one value it seems. So how can I return multiple ones to a sub? You might want want to rethink the structure of you application, if you really, really want one method to return multiple values. Either break things apart, so distinct methods return distinct values, or figure out a logical grouping and build an object to hold that data that can in turn be returned. ' this is the VB6/VBA equivalent

MS Word Macro to increment all numbers in word document

烂漫一生 提交于 2019-11-29 17:44:43
I am trying to make a MS-word Macro to increment all numbers in the word document which are within brackets, eg original numbers [1] [2] [3] [4] , after incrementing all numbers by 10, above numbers will be changed to [11] [12] [13] [14] I'm stuck in the code below and not familiar with VBA before. Can anyone suggest, what to add in code below to perform above macro?? Sub IncrementNumbers() ' ' IncrementNumbers Macro ' ' Application.ScreenUpdating = False Dim RngStory As Range, StrStart As String, StrEnd As String StrStart = "[" StrEnd = "]" Set RngStory = ActiveDocument.Range With RngStory

Cannot instanciate a NotesUIWorkspace from VBA (Word)

守給你的承諾、 提交于 2019-11-29 17:33:12
The source situation: I have an Notes Application which uses MS Office 2000 under Windows XP. The new situation has to be MS Office 2010 under Windows 7. IBM Notes is 8.5.3FP3. The old one uses a VBA template to communicate with Notes which works properly. At one time a Notes.NotesUiWorkSpace object is created to open a document, navigate to a richtext item, select all the content (formatted) and copy to the clipboard. Then the clipboard content ist pasted into the Word document via VBA. That works fine. The same code in the second environment doesn't work anymore. I noticed that the Notes

Searching for Text in Header Section of A Word Document

旧城冷巷雨未停 提交于 2019-11-29 16:09:17
I am trying to confirm if a document contains some text, the only problem is this text is in the Header. This is the code I am using which constantly returns false even though the text exists: Set CurrentDoc = Documents.Open("a.doc") With CurrentDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Find .Text = "This is the text to find" .Forward = True .Execute If (.Found = True) Then Debug.Print "Match" End With The following also doesn't seem to work (I assume .Content doesn't include header/footers): With CurrentDoc.Content.Find .Text = "This is the text to find" .Forward = True .Execute

With a Word ContentControl DatePicker how do i get the value?

元气小坏坏 提交于 2019-11-29 15:32:08
I have a ContentControl that is a DatePicker in a word document. I'm trying to use it to populate some value in a code behind but I cant seem to get the value out of it. Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, _ Cancel As Boolean) None of the properties on ContentControl are close to .Value or .Text. I have seen other content controls use: ContentControl.DropdownListEntries(1).Text ContentControl.DropdownListEntries(1).Value This, as expected for a DatePicker, does not work but it is the only property of ContentControl that returns anything close to

A good substitute for references/pointers in VBA?

天大地大妈咪最大 提交于 2019-11-29 13:54:24
Can you recommend me a good substitute for reference or pointer types in VBA? I have been struggling for long with expressions like this: dblMyArray( i * lngDimension0 + j * lngDimension1 + k * lngDimension2, l * lngDimension3 + m * lngDimension4 ) = dblMyArray( i * lngDimension0 + j * lngDimension1 + k * lngDimension2, l * lngDimension3 + m * lngDimension4 ) + 1 If I wanted to accumulate values in a multidimensional array in e.g. C++, I could write this: double& rElement = dblMyArray[ i * lngDimension0 + j * lngDimension1 + k * lngDimension2 ][ l * lngDimension3 + m * lngDimension4 ];

Word VBA - DocumentBeforeSave event?

人走茶凉 提交于 2019-11-29 12:58:35
I am using the following VBA code to make a message box appear while saving the Word document, Public WithEvents appWord as Word.Application Private Sub appWord_DocumentBeforeSave _ (ByVal Doc As Document, _ SaveAsUI As Boolean, _ Cancel As Boolean) Dim intResponse As Integer intResponse = MsgBox("Do you really want to " _ & "save the document?", _ vbYesNo) If intResponse = vbNo Then Cancel = True End Sub This code was written in a Class. But this does not work. Nothing happens when saving. What is the issue here? Codename K I made it to work. Thanks to AnalystCave.com for the help. This is

Word occurences in VBA: how to speed up

橙三吉。 提交于 2019-11-29 12:58:34
I need to write a MS Word macro to count occurence of every word within a given document and print out the list like . I did the macro and it works, but it is so sloooow, it takes several hours to get results for a document of 60000 words. Could you please give me some advices/suggestions on how to make the macro run faster? (I checked a similar question here WORD VBA Count Word Occurrences but still don't get it how to speed up and need my macro to be reviewed). Thank you. Private Type WordStatData WordText As String WordCount As Integer End Type Option Base 1 'Check if the word is valid

VBA WORD: Remove double paragraph marks

旧街凉风 提交于 2019-11-29 12:51:55
Trying to move excessive paragraph gaps via this procedure. Sub RemoveGaps() wrdDoc.Content.Select Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^13^13" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = True .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll If Selection.Find.Found = True Then Call RemoveGaps End If End Sub After I run it the loop never ends and I end up with this kind of formation at the bottom of the document. Note that it does