word-vba

Word 2003 mailmerge to separate files or print to PDF

I created a mailmerge from a single page which resulted in one document with about two hundred pages. What I need is a way to create separate files for each of these. The way I see it, I have two options: Create about 200 Word documents I can print directly to PDF (Acrobat Distiller installed). with PDF printer set as default, I can t...

How to Programmatically Enable Trust for VBA Project?

Getting the following error when trying to open a word document with macros to fill in the form fields: HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Word\Security\AccessVBOM The user opening the word document does not have admin rights and the AccessVBOM flag is either not available or set to zero. I can set the flag for the HKCU p...

Word 2007 macros: is there an OnPrint event I can attach a macro to?

I'm looking to do a formatting check on word files before they get sent to the printer and it needs to be completely transparent to the user (no extra controls, just using the standard print options available through the UI). Is there an OnPrint or BeforePrint event, or something that can be used in that respect which I could attach a m...

Run-time error 459 when using WithEvents with a class that implements another

I am developing a VBA project in Word and have encountered a problem with handling events when using a class that implements another. I define an empty class, IMyInterface: Public Sub Xyz() End Sub Public Event SomeEvent() And a class, MyClass that implements the above: Implements IMyInterface Public Event SomeEvent() Public Sub ...

Updating/creating Table of Contents in Word using VBA

I'm new to VBA. I'm trying to update the Table of Contents in my Word document everytime I open the document, but it does not seem to update it at all. In ThisDocument I've done the following: Private Sub Document_Open() ActiveDocument.TablesOfContents(1).Update End Sub Can anyone help me? ...

Make the first letter bold on each sentence in MS Word document

I'd like to make first letter on each sentence bold in a MS Word document. What would be a good way to accomplish this? ...

Word 2007 VBA: ActiveDocument.CustomXMLParts

In this tutorial (and many others), there's an integer in the CustomXMLParts object collection Load method that I can't find an explanation for. The Word 2007 VBA Reference doesn't seem to list the Load method either: ''# Load CustomerData.xml file ActiveDocument.CustomXMLParts.Add ActiveDocument.CustomXMLParts(4).Load ("c:\Custo...

Word 2007 VBA: ActiveDocument.CustomXMLParts and Drop-down lists

Unsure of the best way to bind a a drop-down list Content Control to an XML file properly: all I'm getting is the first item. I'm assuming I'll have to iterate through the XML document, count number of items, and then call the .Add method on the control accordingly, but I'm not sure how to do that in VBA. Here's what I have: Dim ap ...

Generate word documents from excel file using mail merge

Hello I am trying to generate word documents using the mail merge feature in Microsoft Word. To be as clear as possible my dream would be to: (1) Place all values for all documents to be created in one excel document (2) Use Word to create a template by selecting the above excel file as the data sheet (3) Run a macro that would use th...

Cannot turn off Design Mode in Word VBA

I'm stumped about this thing - when recording a macro where I basically add some fields and go into Design Mode to be able to replace the dummy text of the placeholder. Now, I go out of Design Mode when recording the macro and everything seems to be working ok. But when playing the macro, it just stops after ActiveDocument.ToggleFormsDes...

Where do I get started with VBA and macros programming in Word 2007?

I just came to know that macros in Word/Excel/PowerPoint can be programmed. That is awesome because I've a Word document with 70 tables for styling. I'm a programmer but I don't know VB, VBA or VB .NET. I'm confused with these three. I'm familiar with .NET programming using C#. Now I want to write new macros. Where should I get started?...

How can I programmatically bring up the document properties window in Word and go to the Summary tab?

I am developing a VB6 COM add-in for Microsoft Word and I have added a button to the Ribbon which will save the document to a database. But before the document is saved, I want to take the user to the document properties window so they can fill in the properties for the document (like Title, Subject and Author). I am using the followin...

Misspellings in Microsoft Word

I am working with misspellings in Microsoft Word. With only just a few misspellings, accessing the SpellingErrors collection becomes gawdawful slow (at least with For/Next or For/Each loops). Is there a way to get the to the list (make a copy, copy the entries, stop the dynamic nature of the collection) quickly? I just need a list, a sn...

How to extract specific tables from a MS-Word document using VBA?

VBA is a programming language so I'll assume this question is ok on SO. What API calls and other techniques can I use, to extract specific tables from an MS-Word document? I need to write a program which will open several Word documents, and look inside for tables which have a certain text in Row 1 Column 1, and output those tables to ...

Opening Word (from Outlook VBA) in Safe Mode

I have a Word document as an attachment to an email that I need to get some data out of to pass to a URL. To do this I'm saving the attachment to the local temp file, then opening the document, and then using the Word object model to pull data out of tables in the document. I'm having a couple of problems when opening the document in V...

Word 2007 VBA: Documents.Add results in template being locked

I have a simple macro that creates a new document based on a template that's stored on a network share; this macro is stored in each user's Word\STARTUP folder as the file "macros.dotm" and is executed by a button added to their toolbar. The problem I have is that the template file gets locked as soon as the macro code (see below) is e...

How to access group matches in search macro that uses wildcards?

In a Word 2007 macro that finds text using wildcards, how do I access the group match values? For example, if I script a macro that searches for DATE: (<*>)^13, how would I find the value of the match group (<*>)? Thank you, Ben Sub Search() Selection.Find.ClearFormatting With Selection.Find .Text = "DATE: (<*>...

Word vba - How can I store string values in a module?

Hi, the title may not be appropriate because I don't really know how I should put this. I have a template where I have a "Module1" module and a "ThisDocument" code. Module1 contains the following code to pick up values from the registry. I pick up these values from ThisDocument code. What I want is to move the code from ThisDocument ov...

Read INI values only once in Word VBA

I've trying to simplify a script and it's routines and I'm not quite sure what's the best way of doing it. I want to repeat code as little as possible. So below is my current code. This is the Filename function that basically checks if an ini-file exists. It should probably just run once. The way it's now, it's run everytime the string ...

Word 2007 vba - Styles arent applied via macro

Hi, this is so weird. I have a macro code that basically creates a few tables, then types in some text in some of then, and then places a few text placeholders. The problem appear when I try to apply styles to the text. At first I thought it was only the placeholders that aren't affected by the code. But it seems as though regular text, ...