Tulsi
Tulsi

Reputation: 151

Remove unwanted section breaks from Word?

I am trying to create an envelope in MS Word. The following code will create an envelope, but I get "section break (Next Page)" at the top of that page. I would like to remove that.

 oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                oDoc.Activate();
                object ExtractAddress = false;
                object Address = "Address" ;
                object AutoText = "AutoText" ;
                object OmitReturnAddress = false;
                object ReturnAddress = "ReturnAddress" ;
                object ReturnAutoText = "ReturnAutoText";
                object PrintBarCode = false;
                object PrintFIMA = false;
                object Size = "E65";
                object Height = 110;
                object Width = 220;
                object FeedSource = true;
                object AddressFromLeft = 2;
                object AddressFromTop = 2;
                object ReturnAddressFromLeft = 2;
                object ReturnAddressFromTop = 2;
                object DefaultFaceUp = true;
                object DefaultOrientation = Microsoft.Office.Interop.Word.WdEnvelopeOrientation.wdCenterPortrait;
                object PrintEPostage = false;
                object Vertical = false;
                object RecipientNamefromLeft = Missing.Value;
                object RecipientNamefromTop = Missing.Value;
                object RecipientPostalfromLeft = Missing.Value;
                object RecipientPostalfromTop = Missing.Value;
                object SenderNamefromLeft = Missing.Value;
                object SenderNamefromTop = Missing.Value;
                object SenderPostalfromLeft = Missing.Value;
                object SenderPostalfromTop = Missing.Value;
                oDoc.Envelope.Insert(ref ExtractAddress, ref Address, ref AutoText, 
                    ref OmitReturnAddress, ref ReturnAddress, ref  ReturnAutoText, 
                    ref  PrintBarCode, ref  PrintFIMA, ref  Size, ref  Height, 
                    ref  Width, ref  FeedSource, ref  AddressFromLeft, ref  AddressFromTop, 
                    ref  ReturnAddressFromLeft, ref  ReturnAddressFromTop, ref  DefaultFaceUp,
                    ref  DefaultOrientation, ref  PrintEPostage, ref  Vertical, 
                    ref  RecipientNamefromLeft, ref  RecipientNamefromTop, 
                    ref  RecipientPostalfromLeft, ref  RecipientPostalfromTop, 
                    ref  SenderNamefromLeft, ref  SenderNamefromTop, ref  SenderPostalfromLeft,  
                    ref  SenderPostalfromTop);

Upvotes: 3

Views: 1231

Answers (1)

Doc Brown
Doc Brown

Reputation: 20054

After fiddeling around with the envelope feature of Word, I noticed that this is not a programming question (although you made it looking like one). If you insert an envelope manually into a document, you will get also a section break, which splits the envelope part from the rest of the document, since both have different paper sizes. I did not find an easy way to get rid of that section break easily while still keeping the envelope size intact, so here is my advice to get this right:

  • don't use the "envelope" feature of Word
  • adjust paper size and margins manually (in Word, using the menus/ribbons), and place your Address and return address at the positions where you want them to be
  • use the macro recorder to record the VBA commands to do this
  • port the VBA code to C#

Upvotes: 1

Related Questions