1. Home
  2. Computing & Technology
  3. Visual Basic

VBA - The Word Working Partner - Part 1

By , About.com Guide

4 of 7

Automate Your Letter Writing

The trick that we used on the previous page opens the door to lots of useful applications. For example, if you use Word mainly to write letters and only occasionally for something else, you could write an AutoExec program to ask whether to load a default "personal letter" or the generic Word environment.

~~~~~~~~~~~~~~~~~~~~~~~~~
Public Sub AutoExec()
  Dim MsgBoxResult
  Dim SaveFileName
  MsgBoxResult = _
    MsgBox( _
    "Click Yes to load the default letter" _
    & vbCrLf & _
    "Click No to load default Word.", _
    vbYesNo, "Document Environment")
  If MsgBoxResult = vbYes Then
    Documents.Open _
      ("C:\DefaultLetter.doc")
      SaveFileName = _
        InputBox( _
        "Enter a name for the letter", _
        "Letter Name ?")
      If SaveFileName <> "" _
        Then _
        ActiveDocument.SaveAs (SaveFileName)
  End If
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~

Explore Visual Basic
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB 6
  5. Learn VBA
  6. VBA - The Word Working Partner - Part 1

©2009 About.com, a part of The New York Times Company.

All rights reserved.