Font popup

L

LDMueller

In Word 2003, I have a basic macro which goes to Page 2, then inserts a
header. At this point I need a popup or something to prompt for a font
change. My sample code is as follows. Can anyone assist me? Thanks!

Sub Header()

'Go to page 2
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="2"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With

'Insert header
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
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.TypeText Text:="Prompt for font"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
 
D

Doug Robbins - Word MVP

Why don't you set up the header in the template from which the documents are
being created. Also note that a header that you insert in a documnet in
this manner will appear on page one as well, so why bother going to page 2

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

LDMueller

Hi Doug,

These letters are written by our attorneys, then given to the secretaries to
finalize. The code I sent you is very basic so I could focus on the font
popup part. My actual code does more including has a userform popup to allow
them to select a static date or not.

My problem is when the secretaries format the letter, it may be in a
different font that their default font. As it is now, the second page header
is using the default font which won't work. This is why I needed a popup or
something to allow them to change the font.

Thanks!
 
J

Jean-Guy Marcil

LDMueller was telling us:
LDMueller nous racontait que :
Hi Doug,

These letters are written by our attorneys, then given to the
secretaries to finalize. The code I sent you is very basic so I
could focus on the font popup part. My actual code does more
including has a userform popup to allow them to select a static date
or not.

My problem is when the secretaries format the letter, it may be in a
different font that their default font. As it is now, the second
page header is using the default font which won't work. This is why
I needed a popup or something to allow them to change the font.

First, I world not ask the user to type a font name, any typo will make the
code unworkable.
Second, avoid the selection object, especially when dealing with headers and
footers
Finally, as Doug pointed out, as is, your code will nor work.

Play around with this:

'_______________________________________
Option Explicit
'_______________________________________

Sub checkFont()

Dim strUsedFont As String
Dim rgePara As Range
Dim lngParaCount As Long

With ActiveDocument
'Get font name from middle para in doc
lngParaCount = .Paragraphs.Count
lngParaCount = lngParaCount / 2

strUsedFont = .Paragraphs(lngParaCount).Range.Font.Name

'if more than one font is used in the target paragraph
'then strUsedFont will equal ""
If strUsedFont = "" Then
'in which ncase, get font name from first character
strUsedFont = .Paragraphs(lngParaCount).Range _
.Characters(1).Font.Name
End If

With .Sections(1)
.PageSetup.DifferentFirstPageHeaderFooter = True
With .Headers(wdHeaderFooterPrimary).Range
.Font.Name = strUsedFont
.Text = "Prompt for font"
End With
End With
End With

End Sub
'_______________________________________

I think you used the macro recorder, in which case, you may want to have a
look at:
http://word.mvps.org/faqs/macrosvba/UsingRecorder.htm
and then:
http://word.mvps.org/faqs/macrosvba/ModifyRecordedMacro.htm

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
L

LDMueller

I was able to manipulate your code to get exactly what I needed.

Thank you so much for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top