word-vba

Formatting text from Mulitline text box in word with VBA

Hello all, I'm putting together a template in Word, using a form for the user to fill in to then populate some of the document. The bit I'm currently stuck on is at the end of the document, where the cc's are listed. The form has a multiline text box into which the user puts in their cc's, one per line. I then want to add to the end ...

Can you reposition images in Word 2007 using VBA?

I'm trying to write a macro that will reposition all images in a Word document to, say for example, the very top left hand side of each page. Is that possible? ...

How to apply macro at end of every heading in MS Word?

I have a document with various headings (so not necessarily Heading 1 or Heading 2 - but all types of headings). What I'm trying to do is write a macro that will, for example, delete 2 spaces at the end of each heading. For example, we have This is a heading At the end of heading, I will do: Selection.Delete Unit:=wdCharacters, Coun...

Word 2007 form fields unprotect document via VBA clears all fields but not in Word 2002 version

I have VBA code that prints a word document generated from a word template with form fields and then has to unprotect it to change the header and print the doc again. When I unprotect the doc to change the content of the header all form fields are cleared. But: When I use a Word 2002 doc that just got saved as the 2007 dotm format everyt...

MailMerge script to merge headers/footers?

I'm writing a script to merge 2 Word templates into 1 master document, depending on some criteria. This is what I have so far: {if mergefield effort_ } = 5 "{ includtext "C:\\1\\PL5.doc"}" ""{includetext "C:\\1\\PL6.doc"}"} The merged doc works fine, but in my PL5 and PL6 files, I have some headers and footers. The merged doc can only ...

Using VBA how to automatically run a Microsoft Word macro after a merge

What do I need to do to get a macro to run after a Microsoft Word document has been merged? We are using the XML or Word ML format in Office 2003. The Merge is not happening inside of the MS Word Application, it is being merge by another application called SIMS by Capita. How can I get the Macro to run after a merge, when the document...

Disable or Override Ribbon/CommandBar commands in MSWord using VBA

Hi There First of all I'm going to state right out that I've never worked with VB in the context of coding macros before - my skills lie in other areas (PHP, Javascript, getting there with C#, etc). However, I've been asked by a colleague to lock down a document so that the user cannot change font faces, sizes or colours but does still ...

Word doc document.PrintOut won't print to a particular printer

I have the following .js file being run using cscript on Windows Vista with Office 2007: var err = 0; var app = WScript.CreateObject("Word.Application"); try { var filename = WScript.StdIn.ReadLine(); var enc = filename.toLowerCase().indexOf(".txt") >= 0 ? 65001 : 1252; var objDoc = app.Documents.Open(filename, false, true, false,...

Creating autogenerating rows in Word forms

In Word 2003, I am trying to create a form that can generate additional entries if the person filling out the forms requires them. I have tried a form field that runs a macro on entry but that does not seem to be working. Is there a more elegant way to make a form that can add rows in Word as the user requires? Essentially something lik...

Generate a blank table on form check in Word 2003

In Word 2003, I am trying to create a form that can generate additional entries if the person filling out the forms requires them and clicks a checkbox stating (for additional tables click here). I have tried a form field that runs a macro on entry but that does not seem to be working. Is there a more elegant way to make a form that can ...

How can I programatically (VBA) copy an excel slide to a Word document

Goal: Step 1. Use a PowerPoint presentation during a seminar that allows the presenter to click on text fields and fill in information while still in "slideshow" view. Step 2. Copy (in any way) the entered information to a word document. Currently one the slide in question I have a table in powerpoint with msotextboxes overlayed over ...

Visual Basic Macro in Word to Resize/Center/Delete All Images

I found a VBA macro online that resizes all the images in a Word document: Sub ResizeAllImages() ''# make all images (both inline and floating) ''# 11 cm wide while preserving aspect ratio Dim oShp As Shape Dim oILShp As InlineShape For Each oShp In ActiveDocument.Shapes With oShp .Height = AspectHt(.Width, .Height, _ ...

Copy Text from Range in Excel into Word Document

hi, how do you: 1) copy text from a range in an Excel Document. 2) Open a Word Document. 3) inserts the text into a specific part of the word document. regards Kojo Edit: here is the approach Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Dim j As Integer Set wrdApp = CreateObject("Word.Application") wrdApp.Visi...

How do i make a string bold

hi, I'm creating a word document programatically using VBA. 1) I have a a string with value - "Strategy". I want to make it bold and to be displayed in the word document. I have tried this below, but the text is never changed: Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Set wrdApp = CreateObject("Word.Application")...

Add an Image to Word Document and Scale it using VBA

hi, how do i programatically add an image using VBA to a word document. I've tried adding a bookmark to the word document and tried adding the image, but it always adds to the top of the form rather than the bookmark area. Should i persevere with the bookmark or is there another way to add the image? See my code below: Dim wrdApp As...

When is a macro not a macro? (MS Word)

Odd phenomenon started six to nine months ago. Many of my "clients" (non-technical co-workers) create/edit documents for other clients. Part of my job is to minimize things that make them hate technology :-) One of those things is puzzling me. Some of the Word documents, when I open them, warn me that they contain macros. But when I...

Display HTML page in Office 2003 or 2007 task pane via VBA

Is it possible to display an HTML page in an Office 2003 and/or 2007 task pane via VBA? Background: We have a complicated configuration file that our users maintain in Word (using a real editor is not an option for our audience). We would like to create several toolbar buttons that display a basic HTML page in a task pane as a form of ...

Removing Word table border using C#

Hi all, I wanted to perform specific table formatting by removing left, right, inside horizontal and inside vertical borders. I have recorded a macro for this and got the following VBA code. I tried to make the same using C# , but I could not find there properties like wdBorderLeft , wdBorderRight, wdBorderHorizontal or wdBorderVertica...

Practical limits of Word/VBA apps

The company I work for has an internally developed Word2003/VBA application that's already about 6.5 mb in size and they're looking to add an additional 200+ macros to it, which, I'm assuming, will make it much larger. This seems to me to be a terrible idea, but finding resources to redevelop the tool with VSTO or some other more useful ...

Using VBA in MS Word 2007 to define page elements?

I'd like to be able to create a page element which I can feed text and it will form itself into the preferred layout. For instance: {MACRO DocumentIntro("Introduction to Business Studies", "FP015", "Teachers' Guide")} with that as a field, the output should be a line, the first two strings a certain size and font, centred, another lin...