Sunday, March 29, 2009

MOTD: Insert Merge Field

I've posted before about the amazing potential of Word's Mail Merge feature, I use it so much that I've created a macro to insert MergeFields when I'm creating a merge document. I then assign the macro to a shortcut so I can quickly insert these fields in my documents. I simply recorded a macro without editing any code so you can record it yourself using this post and this post, or you can put the following code in the Normal template and assign a shortcut to it (use this post):

Sub InsertMergeField() 'ALT CTRL M
'
' InsertMergeField Macro
' Macro recorded 3/13/2009 by Michael Shubeck
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"MERGEFIELD INSERT ", PreserveFormatting:=True
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Fields.ToggleShowCodes
End Sub

Sunday, March 22, 2009

Macro of the Day (MOTD): Keybord Shortcut For Envelope Printing

I do a lot of envelope printing in my job and I use Word's Envelope Wizard to do most of my envelope printing. I don't know why they have a whole wizard for this though. I would prefer if I could simply highlight the person's address in the letter I was drafting, type a shortcut, and have it print. So, I created a macro. Type Alt + F11 to open the Visual Basic editor. I would put this code in the Normal template. The Normal template is the basis for all Word documents. By putting code there, it will run in any document you are using.

In the Project window on the left side of the Visual Basic editor, open up the Normal tab and the Microsoft Word Objects tab under that. Double click on the ThisDocument icon. Paste the following code in.

Sub PrintEnvelope()
'
' PrintEnvelope Macro
' Macro recorded 3/10/2009 by Michael Shubeck
'
ActiveDocument.Envelope.PrintOut ExtractAddress:=False, OmitReturnAddress _
:=True, PrintBarCode:=False, PrintFIMA:=False, Height:=InchesToPoints( _
4.13), Width:=InchesToPoints(9.5), Address:=Selection.Text, AutoText _
:="ToolsCreateLabels3", ReturnAddress:= _
"The Law Offices of Gregory A. Yates", ReturnAutoText:= _
"ToolsCreateLabels2", AddressFromLeft:=wdAutoPosition, AddressFromTop:= _
wdAutoPosition, ReturnAddressFromLeft:=wdAutoPosition, _
ReturnAddressFromTop:=wdAutoPosition, DefaultOrientation:=wdLeftLandscape _
, DefaultFaceUp:=False, PrintEPostage:=False
End Sub

Now lets hook the macro up to a keyboard shortcut. In Word 2007, click on the Office Button Then click on Word Options at the bottom of the menu that pops out. Then hit the Customize tab. Finally, at the bottom of the Customize window, hit the customize keyboard shortcuts button. In the Categories box, scroll down to Macros. Then, in the Macros box, select our PrintEnvelope macro. Now, click in the Press New Shortcut Key box. Type the key combination that you want to assign to the macro. If the key combination is already used it, the window will show text that says "Currently assigned to." Usually I just replace what was assigned by the Microsoft people because they have shortcuts for features I will never use. Finally, hit the Assign button (don't forget this - I do all the time).


Now you can highlight a person's address in your document, use your shortcut, and the envelope will print.

As a final note, watch out where the envelpe prints if you have multiple printers installed. The envelope will print to the printer listed in the print menu.

Sunday, March 15, 2009

MOTD: Autoupdate fields on save

This will be the first of a series of posts on cool Microsoft Word macros I have been using to make me more efficient at producing documents and cut down on embarrassing errors. Bill and I have been preaching the benefits of macros for a while on this blog. Check this post out for an introduction.

I use templates for all of my commonly used documents, from my basic letter or fax template to more complex pleading documents. I have discussed how to create templates before. Word allows you to insert blanks called fields in a document. These fields will automatically fill in information at certain times. In many of my templates I have fields that automatically fill in the date or generate tables of contents, among other things. These fields all need to be manually updated by right clicking on them and clicking update. Sometimes I forget to update the field before printing so I created a macro to automatically update the fields when I hit the save button. Credit goes to these blog posts: 1, 2.

For experimentation, create a template using the procedures from the creating templates tutorial. Then insert a save date field in that template. In Office 2007, you go to the Insert tab on the Ribbon bar . Next, go to the Quick Parts button . Then select the Field menu item.


In the Field dialog, select
SaveDate. Select whatever date format you desire.


A SaveDate field displays the date the document was saved (after it is updated) and, thus, is handy for letters and other documents that are printed and sent on the date they are saved.

Now lets bring up the Visual Basic editor so we can start adding some code, type Alt + F11. In the Project window on the left, find the letter project and right click on it. Next click insert -> module.

A new item called a code module will be inserted under your project in a modules folder. It will be named Module1.

Now insert a new class module just like you inserted the code module. The class module will be named Class1.

Your Project window should look like this:





The specifics of what ThisDocument, Module1, and Class1 are not very important at this point so I wont go into detail. We will just paste code to make things work. If you have a desire to understand code, see here.

Double click on the ThisDocument icon in the Project window. Now paste the following code into the code window:

Private Sub Document_New() 'has to be Document_New not Document_Open for it to work in a template

    Call Register_Event_Handler

End Sub

Now double click on the Module1 icon and paste this code in:

Dim X As New Class1
Public Sub Register_Event_Handler()
    Set X.App = Word.Application
End Sub

Finally, paste this code into Class1:

Public WithEvents App As Word.Application

Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)

UpdateAll

End Sub

Sub UpdateAll()
Dim oStory As Range
Dim oField As Field
Dim bSaveDate As Boolean
bSaveDate = False

On Error Resume Next
For Each oStory In ActiveDocument.StoryRanges
For Each oField In oStory.Fields
If oField.Type = wdFieldSaveDate Then
    bSaveDate = True
End If
oField.Update
Next oField
Next oStory
If bSaveDate = True Then
    MsgBox "Save a second time to update a save date field"
End If
On Error GoTo 0
End Sub

SaveDate fields present a special paradox. The document has to be saved before the field can be updated. I have the following code to remind me to press save twice to update the field:
If bSaveDate = True Then
    MsgBox "Save a second time to update a save date field"
End If


Now save the template and double click on the template file to create a new document using that template. When you hit save the message box will remind you to save a second time, and when you do, the date field will be updated automatically.

This same code will automatically update tables of contents, numbering and any other Word field that automatically generates information.

Thursday, February 19, 2009

Word shortcut of the day: Ctrl+Shift+A

Hello there, it's been a while.  Just wanted to stop by amid my dilligent work protecting the rights of innocent South Dakotan's to pollute and drop by a little tip I thought needed sharing.

When you're working in Word and you need a section in all capitals select it and press Ctrl+Shift+A.  The same combination returns it to the normal case setting.  I use this in my captions and for section headings in briefs quites a bit.  Hope it helps.

See you in another 6 months! just kidding (hopefully)

Monday, February 16, 2009

Sync Mobile Contacts to Gmail

Google has finally implemented something that users have been requesting for years, synchronization of mobile phone contacts and calendar items with gmail. Google previously released Google Calendar Sync, which synchronizes between Outlook and Google calendar. This allowed you to bounce Google Calendar items off Outlook and onto a mobile phone. Now you can synchronize directly between your phone and Google, AND contacts will be synchronized.

Now our appointments and contacts can be backed up, readily accessible from anywhere, and easily edited from a PC.

You can find instructions here. I had trouble setting up my Windows Mobile phone the solution is here.

Saturday, February 14, 2009

Autogenerate Table of Contents in Word

So its that time again and the poor first years are writing briefs in Appellate Advocacy. One of the most frustrating things was creating a table of contents and table of authorities and have all the pages right - especially forgetting to update after an edit.

Auto Generate Table of Authorities
West provides a utility called WestCiteLink that takes the pain out of the table of authorities. There is a Firefox plugin called CiteGenie that is supposed to take the pain out of citation. Bill recommended CiteGenie but I haven't had the time to test it.

Auto Generate Table of Contents
Word has a function that will generate your table of contents automatically. To use it we first have to become familiar with styles. In Word 07, you can find the styles buttons under the Home heading (because the first thing I think of when I think "Home" is styles and fonts etc. - good job M$). In earlier versions of Word, styles can be found under Format->Styles and Formatting (now that makes sense). We are going to be using the heading styles that look like this:



Type some text into a blank word document, highlight the text, and then click on the style you want to apply. As a result, your text looks like the style you selected:


I have created two headings, one with the Heading 1 style, and the other with the Heading 2 style. Word will put all my headings that have been set to a certain style into a table of contents, complete with page numbers.

First click at the place in the document where you want your table of contents. Go to the References tab in Word 07 (go to Insert->Reference->Index and Tables in earlier versions of Word). Then click on Table of Contents:

Then select one of the Automatic tables. Your table of contents is automatically generated.

Customizing Your Styles
Its probably not a good idea to have your brief headings the funky colors, sizes, and fonts that Word defaults to so we will want to customize the heading style.

In Word 07, highlight your heading, right click on it, and select Styles->Save Selection as New Quick Style (in earlier versions, right click in the styles menu and select modify):

Under name, type a name for your style. Then click Modify. The modify window will pop up and you can set the font, size, and color settings the way you want them.


For numbered headings, click the Format button and select Numbering. In the Numbering window, pick the numbering type you want.


When all is finished, you can simply add more headings and then right click on your table of contents and hit update table.


Then select Entire Table (don't just update page numbers). Your table will automatically add the new headings and the right page numbers.


Friday, October 31, 2008

Make XP remember your open folders from the previous session

If you're like me you virtually always have the same folders open.  Previous versions of Windows would restore any folders you left open at the end of your previous session.... phew, that's a mouthful.  In other words, If you keep the same folders open regularly, and you want them open when you restart, then follow these steps in any folder.

1. Click Tools
2. Click Folder Options
3. Click the View tab
4. Scroll down and check the checkbox beside "Restore previous folder windows at logon"
5. Click OK, and you're good.