Delete Page Break in word using VBA in excel

excelpunk

Board Regular
Joined
May 6, 2011
Messages
165
Hello All!

I have a word template which is of 2 pages, it has just one page break, I have vba code in Excel, which opens this template, manipulates something and then saves the template with a different name.

However, I have now realized that in some cases I need to delete that page break. What vba code should I include to make this happen.

My apologies if the post is not relevant.
 
Thanks again! This worked the way I wanted. Just amazing! Thanks.

Just a couple of queries:

Can you tell me what went wrong with the code I tried with:
with wordtemp.activedocument.tables(1).Select
'followed by recorded macro
Selection.Sort ExcludeHeader:=True, FieldNumber:="Column 1", SortFieldType _
:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, FieldNumber2 _
:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
wdSortSeparateByCommas, SortColumn:=False, CaseSensitive:=False, _
LanguageID:=wdEnglishUS, SubFieldNumber:="Paragraphs", SubFieldNumber2:= _
"Paragraphs", SubFieldNumber3:="Paragraphs"

Also, do you have links to any resources where controling word from Excel is explained?
I dont understand why the recorded macro throws error when I use it from Excel! The same code works fine when I use it in word modules. Strange!
Not sure exactly where it faults without seeing of your full code, but there are a plenty of Word's constants in that code started with wd which are not known for Excel.
You need do redefine it all in the Excel code (see my example of Const ...), or replace it all by its numeric values (in Word select the constant and press F2), or use Early Binding and set reference to MS Word via Excel VBE - References.
MacroRecorder builds raw code with unwanted selections, using of Range is faster and preferable as well as for the Excel code.

To find resources try googling How to automate Microsoft Word from Excel
 
Last edited:
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,216,100
Messages
6,128,834
Members
449,471
Latest member
lachbee

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