Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-09-2011, 04:32 PM
Coreysan Coreysan is offline Word Merge from Excel not in same order! Windows 7 64bit Word Merge from Excel not in same order! Office 2010 64bit
Novice
Word Merge from Excel not in same order!
 
Join Date: Dec 2011
Posts: 10
Coreysan is on a distinguished road
Default Word Merge from Excel not in same order!

I have an excel file with 10 records in sorted order. When I perform a Word merge manually (using the Word ribbon) then the output in Word shows all the 10 pages in exactly the same order as the records in Excel.
So, if excel has records 1-10, then the Word doc shows pages 1-10 in the same exact order.



However, if I perform the merge programmatically in C#, then the Word pages are not in the same order. So, if Excel shows records 1-10, the Word doc might show page 4, then page 9, then page 2, etc.

How can I programmatically get the Word doc pages in the exact same order, so that when I print, they print out in the same order as the excel records are in?

Here's some code I use:

publicvoid Open_Word_File(string wdoctemplatefile2)
{
wrdApp =
new Microsoft.Office.Interop.Word.Application();

wrdApp.Visible =
false;
oTempFilePath = wdoctemplatefile2;
oMissing = System.Reflection.
Missing.Value;
oFalse =
false;
//Open the Word Template
wrdDoc = wrdApp.Documents.Open(ref oTempFilePath, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
wrdDoc.Select();
}


publicvoid Open_Excel_File(string wfilename)
{
//Word.MailMerge wrdMailMerge = wrdDoc.MailMerge;
wrdMailMerge = wrdDoc.MailMerge;
object mysql = "select * from [sheet1$] order by idx";
wrdMailMerge.OpenDataSource(wfilename, oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref mysql, ref oMissing, ref oMissing, ref oMissing);
}

publicvoid Perform_Word_Merge()
{
// Perform mail merge.
wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
wrdMailMerge.Execute(
ref oFalse);
}
Reply With Quote
  #2  
Old 12-10-2011, 01:04 AM
macropod's Avatar
macropod macropod is offline Word Merge from Excel not in same order! Windows 7 64bit Word Merge from Excel not in same order! Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Coreysan,

What is 'idx' and happens if you delete 'order by idx'?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-11-2011, 12:22 PM
Coreysan Coreysan is offline Word Merge from Excel not in same order! Windows 7 64bit Word Merge from Excel not in same order! Office 2010 64bit
Novice
Word Merge from Excel not in same order!
 
Join Date: Dec 2011
Posts: 10
Coreysan is on a distinguished road
Default Word Merge from Excel not in same order!

The select statement is actually irrelevant. It exhibits the same behavior with or without the reference to "order by idx", which is column 1, in numbered order; an indexed numerical column.

I have this problem no matter what I try or don't try.

Any suggestions?
Reply With Quote
  #4  
Old 12-11-2011, 04:22 PM
macropod's Avatar
macropod macropod is offline Word Merge from Excel not in same order! Windows 7 64bit Word Merge from Excel not in same order! Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Coreysan,

Unless your code is opening a different version of the Excel file, with a different sort order, I can't see why it would generate a different result.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Merge from Excel not in same order! Word mail merge from a protected Excel worksheet Platform Mail Merge 10 09-28-2011 05:12 AM
Word Merge from Excel not in same order! Merge excel info into word letter. curatorfm Mail Merge 1 03-20-2011 04:26 AM
Word Merge from Excel not in same order! Word Merge Connection to Excel failing techexpressinc Mail Merge 3 01-26-2011 01:27 PM
Reverse order of headings throughout Word my_vine_figtree Word VBA 1 08-17-2010 01:46 AM
Help with switches: Word mail merge with Excel ks_ Mail Merge 0 12-09-2009 05:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft