Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-16-2022, 10:33 PM
kenny84 kenny84 is offline How to move Section 1.0 (Heading 1) into third page in vba word Windows 10 How to move Section 1.0 (Heading 1) into third page in vba word Office 2016
Novice
How to move Section 1.0 (Heading 1) into third page in vba word
 
Join Date: Jan 2022
Posts: 6
kenny84 is on a distinguished road
Default

Hi Guessed,



Thanks for the guidance. I tried first one which change all heading it's work.
Second choice doesn't work for my files and dont have any message error when running the code. Would like to ask about your comment regarding to my code as below:

Sub UpdateDocumentHeaders()

Application.ScreenUpdating = False

Dim strFolder As String, strFile As String
Dim wdDocTgt As Document, wdDocSrc As Document
Dim Sctn As Section, HdFt As HeaderFooter


strFolder = GetFolder

If strFolder = "" Then Exit Sub

Set wdDocSrc = ActiveDocument

strFile = Dir(strFolder & "\*.doc", vbNormal)

While strFile <> ""


If strFolder & "" & strFile <> wdDocSrc.FullName Then
Set wdDocTgt = Documents.Open(FileName:=strFolder & "" & strFile, _
AddToRecentFiles:=False, Visible:=False)

With wdDocTgt

For Each Sctn In .Sections
'For Headers
For Each HdFt In Sctn.Headers
With HdFt
If .Exists Then
If Sctn.Index = 1 Then
.Range.FormattedText = _
wdDocSrc.Sections.First.Headers(HdFt.Index).Range. FormattedText
.Range.Characters.Last = vbNullString
ElseIf .LinkToPrevious = False Then
.Range.FormattedText = _
wdDocSrc.Sections.First.Headers(HdFt.Index).Range. FormattedText
.Range.Characters.Last = vbNullString
End If
End If
End With
Next



'For footers
For Each HdFt In Sctn.Footers
With HdFt
If .Exists Then
If Sctn.Index = 1 Then
.Range.FormattedText = _
wdDocSrc.Sections.First.Footers(HdFt.Index).Range. FormattedText
.Range.Characters.Last = vbNullString
ElseIf .LinkToPrevious = False Then
.Range.FormattedText = _
wdDocSrc.Sections.First.Footers(HdFt.Index).Range. FormattedText
.Range.Characters.Last = vbNullString
End If
End If
End With
Next

'For Heading 1 start at page 3

wdDocTgt.Range.GoTo(What:=wdGoToHeading, Which:=wdGoToFirst).ParagraphFormat.PageBreakBefor e = True

wdDocTgt.PageSetup.FooterDistance = InchesToPoints(0.6)
wdDocTgt.PageSetup.HeaderDistance = InchesToPoints(0.8)

Next



.Close SaveChanges:=True
End With


End If



strFile = Dir()
Wend
Set wdDocSrc = Nothing: Set wdDocTgt = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder( 0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function


Thanks!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to move Section 1.0 (Heading 1) into third page in vba word Word 2007, cannot insert Section Break (Continuous), only Section Break (Next Page) btse1 Word 3 11-01-2018 09:23 AM
How to move Section 1.0 (Heading 1) into third page in vba word Restarting page numbering only if Section begins with Heading 1 kaurp Word VBA 5 11-02-2017 04:36 AM
How to move Section 1.0 (Heading 1) into third page in vba word Changing a Section Heading to an Appendix Heading stardazy Word 2 11-24-2015 01:04 PM
Cross Reference Heading Number with the word "Section" included bblouin Word 5 12-20-2012 05:27 PM
Prefixing heading numbers with custom letters, varying by section, in Microsoft Word? JoelMarcey Word 0 07-23-2011 08:51 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:11 AM.


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