VBA code to ALWAYS have salutation start at 3.8" in Word

kaneda0149

Board Regular
Joined
Aug 4, 2009
Messages
74
I have a mail merge letter document which pre-fills the date, address info and salutation (Dear ___). I need a vba code to ALWAYS have the salutation always start at 3.8" in the letter. The salutation will always be "Dear". For the most part the salutation is at 3.8" but in some cases because of the additional address information (more than the standard 3 lines) it shifts the salutation down to 4.0, 4.1, 4.2, etc... Please help!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
This is untested and uses Wdapp as late binding object (not shown). Not sure if this helps. It will shorten your address to fit line 2 and start "Dear" on line 3 (theoretically). Not sure if this will help but perhaps will get you started. Dave
Code:
Dim Descrip As String, MsgFlag As Boolean
Descrip = "Address string as variable length string"
Above:
With Wdapp.Selection
   .typeparagraph
    .typetext Text:="Line 1" & vbCrLf
    .typetext Text:="Line 2" & vbCrLf
    .typetext Text:=Descrip & vbCrLf
End With

Wdapp.activedocument.paragraphs(5).Range.Select
'check if line number or temp paragraph
'wdFirstCharacterLineNumber=10
If Wdapp.Selection.Information(10) > 5 Then
Wdapp.activedocument.paragraphs(4).Range.Select
Wdapp.Selection.Delete
Wdapp.activedocument.paragraphs(3).Range.Select
Wdapp.Selection.Delete
Wdapp.activedocument.paragraphs(2).Range.Select
Wdapp.Selection.Delete
Wdapp.activedocument.paragraphs(1).Range.Select
Wdapp.Selection.Delete
Descrip = Left(Descrip, Len(Descrip) - 1)
MsgFlag = True
GoTo Above
End If
If MsgFlag Then
MsgBox "Address shortened to: " & Descrip
End If
With Wdapp.Selection
   .typetext Text:="Dear: " & vbCrL
   'etc. rest of letter
End With
 
Upvote 0

Forum statistics

Threads
1,225,415
Messages
6,184,851
Members
453,263
Latest member
LoganAlbright

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top