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

VBA - The Word Working Partner - Part 1

By Dan Mabbutt, About.com

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

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

Easy ways to connect two computers for networking purposes. 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.