Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro in Mailmerge Error

Status
Not open for further replies.

bobsmallwood

Programmer
Aug 9, 2001
38
US
I've created a macro with mail merge in Word 2002 that always creates Microsoft Visual Basic Run Time error 5852: "Requested Object is not available" with a pointer on the command ".Destination = wdSendToNewDocument". Can this be overcome some way?

Here is the code:

Sub ResumeBilling()
'
' ResumeBilling Macro
' Macro recorded 10/21/2005 by Your User Name
'
Documents.Add Template:="X:\WORDPROC\TEMPLATE\Resume-Positions.dot", _
NewTemplate:=False, DocumentType:=0
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
Selection.WholeStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
Documents.Add Template:= _
"X:\WORDPROC\TEMPLATE\Resume-Skills+Posns-Billing.dot", NewTemplate:= _
False, DocumentType:=0
Selection.GoTo What:=wdGoToBookmark, Name:="Positions"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.PasteAndFormat (wdPasteDefault)
Selection.GoTo What:=wdGoToBookmark, Name:="Positions"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
With Selection.Tables(1)
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top