Avatar of FlorisMK
FlorisMKFlag for Netherlands

asked on 

Create Header and Footer from VBA

For a macro that converts existing documents to to the new company design, I need to insert header and footer items. I thought it would be easy, like this:

NormalTemplate.AutoTextEntries("New Company Header").Insert ActiveDocument.StoryRanges(wdPrimaryHeaderStory), True

However, this line gives a run-time error if the active document doesn't yet have a header. Entering a space into the header by hand solves the problem, but that's not satisfactory, because I want to have the full conversion automated.

I can't find any way in VBA to create header and footer in a document that doesn't yet have them. Anyone?
Visual Basic ClassicMicrosoft Word

Avatar of undefined
Last Comment
GrahamSkan
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo