word-vba

Is there VBA syntax highlighting for opening and closing loops and if statements?

一笑奈何 提交于 2019-12-08 00:44:02
问题 Sorry if this has been asked before but I can't seem to find any information on this. I am working with VBA for automating word documents and I have this huge block of code with tons of "if else" statements, "do while" loops and "with" statements all nested together. When I program using other languages and other IDE's, I can normally click the opening "if" or "while" bracket and get the highlighted closing bracket. This makes it a lot easier to keep track of everything. Is there anything

Progressbar inside userform

风格不统一 提交于 2019-12-07 20:41:16
问题 I am trying make a progress bar inside a userform, instead of having a seperate progressbar, because this seems to be unreliable in the respect if it will be on top or in the background. So the progressbar is working fine, however it makes the whole userform repaint for every update the progressbar does. Is it possible to just refresh the progressbar instead of the whole userform? My current code do look like this: Public Sub progress(pctCompl As Single) Me.Text.caption = Format(pctCompl, "##

Finding heading of chapters in word file and copying individual paragraphs to new word file with VBA

霸气de小男生 提交于 2019-12-07 18:15:07
问题 Since nobody was able to help me with the problem I posted here before (link is below), I am now trying to solve the task through VBA. Finding a heading in word file and copying entire paragraph thereafter to new word file with python To briefly recap, I have a large amount of word files, which I would like to reduce to a more readable size each. In each file, there is one heading that appears several times, always formated as a 'Heading 2'. I look for this specific heading which occurs

How to get list of all bookmark-elements from a Word document to an array in order by location: VBA / Word

老子叫甜甜 提交于 2019-12-07 13:27:17
问题 I want to fetch all the bookmarks in my Word document, and then push them to an array. The bookmarks must be sorted by their location in document not by name. ex. here's a list of bookmarks in a document, [bm_s] (header) [bm_h] (title) [bm_a] (footer) I want the bookmarks to keep their order so that the array will look like as following, array {bm_s, bm_h, bm_a, } ex. how it should not look like below, array {bm_a, bm_h, bm_s, } I got the fetching of all the bookmarks from document working. I

Error 462 in VBA : remote server machine not found

佐手、 提交于 2019-12-07 12:39:42
问题 following code is to read a word file in vba. But its showing an error Error 462 in VBA : remote server machine not found. Sub abc() Dim fileReader As String Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Dim singleLine As Paragraph Set wrdApp = CreateObject("Word.Application") Set wrdDoc = wrdApp.Documents.Open("C:\Documents and Settings\Administrator\My Documents\Downloads\fwfiles\webs.doc") With wrdDoc Dim p As Paragraph For Each p In wrdDoc.Paragraphs fileReader = p.Range.Text

Can't get recursive Range.Find in Word VBA to work

喜欢而已 提交于 2019-12-07 11:37:08
问题 I've been flailing at this for a while and can't seem to come up with a solution. I have to search through a document from start to finish with a wildcard search for custom mark-up. For the sake of the question, we'll say {something} When I find a specific match, it gets replaced with the contents of another string which can also contain mark-up. The mark-up has to be replaced in the order it will appear in the final document AND I have to know the recursion level that each replacement was

Why does VBA code run faster when called from a standard module (instead of a userform)?

烂漫一生 提交于 2019-12-07 09:59:11
问题 Alternate Title: Why does pressing Esc make my MS-Word macro run faster While waiting for some code to run I stumbled across something interesting. Code runs slow... press Esc code runs fast. Example: press Esc immediately after execution - 2 sec to complete don't press Esc at all - up to 30 sec to complete To me this makes no sense. It turns out other people have noticed similar behavior, for example: Pausing VBA and re-running it causes faster execution http://www.vbforums.com/showthread

How can I replace a Microsoft Word character style within a range/selection in VBA?

情到浓时终转凉″ 提交于 2019-12-07 05:49:28
问题 I'm working on a Word 2007 template with a macro that will apply character styles to the selected text. It seemed that the Find/Replace feature would be a good place to start, but I think I've found a bug/limitation that prevents the macro from working as desired. Here's my vba code: Sub restyleSelection() Dim r As Range Set r = Selection.Range With r.Find .Style = ActiveDocument.Styles("Default Paragraph Font") .Text = "" .Replacement.Text = "" .Replacement.Style = ActiveDocument.Styles(

Remove paragraph mark from string

纵饮孤独 提交于 2019-12-06 23:49:42
问题 I have a macro that finds all of the 'Heading 1' styles within my document and lists them in a ComboBox on a UserForm. My problem is that the Find routine I am using is also selecting the paragraph mark ( ¶ ) after the text I wish to copy, and that is being displayed in the ComboBox. How can I remove this from the string? I've tried useing replace() , replacing vbCrLf , vbCr , vbLf , vbNewLine , ^p , v , Chr(244) and Asc(244) with "" , but nothing has succeeeded. For example - sanitizedText =

Word 2010 VBA - Manipulating Numbered Lists

纵饮孤独 提交于 2019-12-06 23:49:01
问题 I'm trying to take a numbered list created in Outlook and manipulate it based on the top-level list items. Unfortunately, the only way I've found to manipulate the list is through the ListParagraph type, which breaks out all list items (including sub-items) equally, instead of having different access for each level in the list. Is there a way to access, in one object, a list item, along with all its sub-items? Thanks. Here's what I'm currently using, which works fine for lists with only one