erik_j_72
asked on
Word Macro - Error 4608
We have a macro that someone created a few years ago to change the footer settings and enter some text in the footer. Some workstations will run it fine and some can't run it at all. On the ones that don't work it just hangs and eventually comes up with an error 4608 on the line indcated below ">>".
Please advise if any changes should be made. All workstations are set up exactly the same with Office 2003 SP3. Thanks.
Please advise if any changes should be made. All workstations are set up exactly the same with Office 2003 SP3. Thanks.
Selection.HomeKey Unit:=wdStory
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Or ActiveWindow.ActivePane.View.Type _
= wdMasterView Then
ActiveWindow.ActivePane.View.Type = wdPageView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(1#)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
End With
>>>>> ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.Font.Size = 8
With Selection.Borders(wdBorderTop)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.ColorIndex = Options.DefaultBorderColorIndex
End With
Selection.TypeText Text:="Suby, Von Haden & Associates, S.C."
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(6.5), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
Selection.TypeText Text:=vbTab & "Page "
Selection.Fields.Add range:=Selection.range, Type:=wdFieldPage
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
What is the text of the error message, please?
Ah. I have just run the code and I get the error.
So, to Anser my own quetion the error message is:
"The command is not available"
Logically, that probably means that there is no next footer.
So, to Anser my own quetion the error message is:
"The command is not available"
Logically, that probably means that there is no next footer.
The macro needs to have more than one page already in the document.
Try this alternative. It isn't always easy to guess the full intention of a recorded macro, but this will set up the footer for the first section for all but the first page. It will do this even if there is only one page, so that when a subsequent page appears, the formatted footer will be there.
Try this alternative. It isn't always easy to guess the full intention of a recorded macro, but this will set up the footer for the first section for all but the first page. It will do this even if there is only one page, so that when a subsequent page appears, the formatted footer will be there.
Sub Written()
Dim ftr As HeaderFooter
Dim sec As Section
Dim rng As Range
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(1#)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
End With
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Set sec = ActiveDocument.Sections(1)
Set ftr = sec.Footers(wdHeaderFooterPrimary)
Set rng = ftr.Range
With rng
.InsertBefore "Suby, Von Haden & Associates, S.C."
.Font.Size = 8
With .Borders(wdBorderTop)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.ColorIndex = Options.DefaultBorderColorIndex
End With
With .ParagraphFormat.TabStops
.ClearAll
.Add Position:=InchesToPoints(6.5), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
End With
.InsertAfter vbTab & "Page "
End With
rng.Collapse wdCollapseEnd
ActiveDocument.Fields.Add rng, wdFieldPage
End Sub
ASKER
I will try out that code and see what happens.
ASKER
I tried the code posted and it did nothing in my document. It didn't give an error but it also didn't create the footer. Am I missing something?
How many pages does the first section of the document have?
As far as I can tell from the code, the first page footer is to be left unmodified.
ASKER
The person who wrote this originally is gone but I believe the intention is to set no footer for the first page, different footer first page, then create the footer for pages 2 and beyond.
The macro should do just that.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
How many pages does the document have? If it is more than two, how many sections?
I did test the code after writing it and before posting it.
I am not sure that I have explained sufficiently that both the reason for your original problem and that the code appears to do nothing are that there is only one page in the first section of the document, so you won't see the footer for subsequent pages.
I have therefore added a macrobutton field to the attached document. Double-clicking this will run the original code, and then call a macro to add enough text to ensure that a second page is created.
PrimeFooter.doc
I am not sure that I have explained sufficiently that both the reason for your original problem and that the code appears to do nothing are that there is only one page in the first section of the document, so you won't see the footer for subsequent pages.
I have therefore added a macrobutton field to the attached document. Double-clicking this will run the original code, and then call a macro to add enough text to ensure that a second page is created.
PrimeFooter.doc