VBA Word - Inserindo cabeçalho e rodapé no documento - Word Footer and Header Code

Inline image 1

Blog Office VBA | Blog Excel | Blog Access |

Como posso automatizar a inserção de um cabeçalho e um rodapé no meu documento do MS Word? 

Tente utilizar o código abaixo:

Sub PutHeader_Footer()
 If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
 ActiveWindow.Panes(2).Close
 End If

 If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
 ActivePane.View.Type = wdOutlineView Then
 Let ActiveWindow.ActivePane.View.Type = wdPrintView
 End If

 Let ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
 Let Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
 Let Selection.TypeText Text:="BERNARDES - Aqui está o cabeçalho! "

 Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldDate
 Selection.TypeText Text:=" "
 Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldTime
 Selection.Find.ClearFormatting

 If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
 ActivePane.View.Type = wdOutlineView Then
 Let ActiveWindow.ActivePane.View.Type = wdPrintView
 End If

 Let ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

 NormalTemplate.AutoTextEntries("Digite o nome do arquivo com o respectivo path").Insert Where:= _
 Selection.Range, RichText:=True
 Selection.TypeText Text:=" "
 NormalTemplate.AutoTextEntries("Criado em").Insert Where:=Selection.Range _
 , RichText:=True
 Selection.TypeText Text:=" "
 NormalTemplate.AutoTextEntries("- Pág. ").Insert Where:=Selection.Range, _
 RichText:=True
 ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub 


Tags: VBA, Word, footer, header, code, cabeçalho, rodapé, inserir



Nenhum comentário:

Postar um comentário

diHITT - Notícias