Computing.Net > Forums > Office Software > Merge to New Doc - Record X to Y

Merge to New Doc - Record X to Y

Reply to Message Icon

Original Message
Name: 24HG_Hoop
Date: September 20, 2007 at 21:07:59 Pacific
Subject: Merge to New Doc - Record X to Y
OS: XP
CPU/Ram: 2800 2G
Model/Manufacturer: clone
Comment:

I'm doing a mail merge macro in Word (from an Excel database) where I specify a range for the records to be merged, from record X to record Y.

Can anybody tell me how to get the "max" number of data fields (rows) that exist, from my .xls database, for use as the upper-end of my range for the mail merge? Right now, I just have it in as ".Lastrecord = 6".

Also - my macro (below) switches from "active" document to the new merged document. Instead of saving it out, I'd like to copy it and paste it into the document I'm working in (the original active document).


Sub MergeAndUpdate()
' Macro to Mail Merge, Update Fields and Save out Summary Sheets to generic output.doc file

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 1
.LastRecord = 6
End With
.Execute Pause:=False
End With
ActiveDocument.Fields.Update
ActiveDocument.SaveAs FileName:="D:\AnyDirectory\output.doc"

End Sub


Thanks in advance,

Hoop


Report Offensive Message For Removal

Response Number 1
Name: DerbyDad03
Date: September 21, 2007 at 06:46:31 Pacific
Subject: Merge to New Doc - Record X to Y
Reply: (edit)

I don't do a lot with Word macros, but would the .RecordCount property work?

.LastRecord = .RecordCount

I replaced your 6 with .RecordCount and it returned 7495, the exact number of rows in the spreadsheet I used as a DataSouce.



Report Offensive Follow Up For Removal

Response Number 2
Name: 24HG_Hoop
Date: October 4, 2007 at 09:41:32 Pacific
Subject: Merge to New Doc - Record X to Y
Reply: (edit)

Awesome - thank you DerbyDad03


Report Offensive Follow Up For Removal

Response Number 3
Name: DerbyDad03
Date: October 4, 2007 at 13:53:23 Pacific
Subject: Merge to New Doc - Record X to Y
Reply: (edit)

I'm glad (and lucky!) I could help.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Merge to New Doc - Record X to Y

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software