word-vba

How to programmatically edit all hyperlinks in a Word document?

Is there a macro, VBA code or VBScript that I can write to edit the urls of all the hyperlinks in my Word document? Either Word 97-2003 or docx format. ...

How can I automatically highlight and extract colored text in MS Word?

I have a bunch of documents that need to be edited. The authors use blue text in some parts of the documents to indicate that those words need to be linked. Thank you cornelius for the highlight text code: Sub HighlightNotBlack() Dim char As Range For Each char In ActiveDocument.Characters If char.Font.Color <> wdColorAutomatic An...

Determine number of columns in a table in Word using VBA

Hi, just a quick question. I've got this table in a Word template which have two columns by default. Then I've got this button the user can press if he wants another column. The macro run inserts several text placeholders and formats certain things automatically. But what I want is some sort of routine which basically checks the numbe...

Recheck Document For Spellings Not Same as VBA Code

I want to recheck the spellings in a document after adding a dictionary. The problem is the following code (mostly from the macro recorder) CustomDictionaries.Add FileName:="c:\test_dictionary.dic" Application.ResetIgnoreAll ActiveDocument.Range.SpellingChecked = False ActiveDocument.Range.GrammarChecked = False does not produce the ...

Disable Word 2010 commands on a document level

We want to disable any and all formatting and insertion commands in Word except for bold and italic in all documents that are created from a certain template. It should not be possible to change styles, insert anything but text, or change character formatting at all (except for the aforementioned bold and italic formats). Is there a way ...

Program the Navigation Pane in Word 2010

I'm trying to find a way to program the new Navigation pane in Word 2010 to change tabs when a user selects a picture in the document. I can capture the selection change with WindowSelectionChange(ByVal Sel As Selection), but I can't figure out how change the tab from "Browse the headings" to "Browse the pages", which is what I want. ...

VBA: Word 2010 - Close Header & Footer Tools with VBA

Hello, I'm using a macro, which inserts a text into the footer. After the macro has finished, the Header & Footer Tools are active, so I'm in the editing mode for the footer. Does anyone know how to close this editmode with VBA? Thanks ...

Extract Data from Word Document to an Excel SpreadSheet

I have a requirement to extract a value from a word document on a daily basis and write it to an excel workbook. I currently do this manually and it is border line regarding the most efficient method for me Using Excel file create a vba script and add any word document references. 2 Using the word navigate to the table “9. STOCKS......

Access Active Document in VBA when document is opening on the intranet

We have old Word templates that were originally written for Word 97. For each new version, we've updated the templates. Now we'll go from Word 2003 to Word 2010, and of course there are problems. The template contains the following code: Private Sub Document_Open() On Error Resume Next If ActiveDocument.Type = wdTypeDocument Th...

Extract Headings and Pagenumber of Table of Contents of a Word Document with VBA

Basically what we have here http://stackoverflow.com/questions/274814/getting-the-headings-from-a-word-document Public Sub CreateOutline() Dim docOutline As Word.Document Dim docSource As Word.Document Dim rng As Word.Range Dim astrHeadings As Variant Dim strText As String Dim intLevel As Integer Dim intIt...

VBA Word Range Operations Seem Different

In using or setting Ranges, some Ranges behave differently that other Ranges. For example, ActiveDocument.Range(10, 20).Select ActiveDocument.Tables(2).Cell(1, 1).Range(10, 20).Select The first line if OK and works as expected. The second line produces an error on the Range statement, although it seems that two lines should be identi...

Trigger MS Word macro after save event

My MS Word 2007 template has a footer with the filename in it. The user is going to open the template and do a "Save As..." to make their document. I want the filename shown in the footer to update immediately to the new filename. Is there an AfterSaveEvent or something that I can use as a hook to start my VBA script that does the upda...

VBA macro to toolbar button in Open Office

Hey! I draw the short straw at work and got tasked with converting all our MS Word templates to OO. All macros seems to work when the template is opened in OO but in MS Word we have a toolbar with the macros assigned to buttons in the toolbar. My question is: Is there a way to add macros written in VBA to a toolbar in OO? thanks! ...

Correlate Range.Text to Range.Start and Range.End

Hi, I'm using regular expressions to search against the plain text returned by the following property: namespace Microsoft.Office.Interop.Word { public class Range { ... public string Text { get; set; } ... } } Based upon the matches I want to make changes to the formatted text that corresponds to t...

How do I copy Data from a excel in to word and keep its formatting

Hi, I have been trying to copy text from excel in to word, and retain the bold formatting on the text, but not the cell. When I try manually copy and paste over a cell the text is copied but not the cell itself. When I try repeat this using vb (as shown below) the cell is also copied over With wrdDoc .Content.Font.Name = "Times Ne...

Run external vba-code in MS Word

Can I link in external code to a Word document? I have a lot of word documents with macros (VBA-code). All with the same code. I would like the code to be run from an external source instead of from within all of those documents. That way, if I have to update the code, I only have one place where I have to do the update. ...

Image quality in "Web Page, Filtered"

Hi, This is an important issue and I would be grateful for a solution. I convert a document (RTF) with several embedded images to HTML with Word 2010. The original quality of all images is 200 dpi. When saving as "Web Page, Filtered", all images are reduced to 96 dpi, despite of what I set in the "Save As" dialog -> Tools -> Web Optio...

Make Word's automatic spell-checking pick up dictionary changes

In MS Word it's possible to add words to a custom dictionary so they're recognized. If a word is not recognized, Word automatically puts a red squiggly line underneath it. If you add that word to the custom dictionary, this line disappears. What I'd like to do is perform this process automatically via a macro. It appears that one has to ...

Strange automation? error in Word2007

Hello all! I'm pulling my hair out because I've run into the following problem with one of my clients: My program uses extensive VBA automation in Word. Macros are saved in a specific Word template that is attached to each document. Some of the macros save the current document to a temporary folder under [User]/AppData/Roaming/... for ...