When these individuals run the document, on exit from the appropriate field,
they are getting either an illegal operation and shutting down, or they get
a run-time error 5234 with a message saying the window is too small.
While the work-around is simple (run maximized and toggle), they would
really like to be able to see both screens at once.
Any thoughts on what would be causing this? The bookmarks are valid, the
fields are properly populated, has anyone heard of MS Word causing a
run-time error based on the size of the window?
Thanks for any advice.
"Steve Z" <szu...@govmail.state.nv.us> wrote in message
news:Oy65nIVCBHA.576@tkmsftngp02...
If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If
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
Selection.TypeText Text:="Claimant Name: "
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="Name"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.TypeParagraph
Selection.TypeText Text:="Social Security Number: "
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="SSN"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.TypeParagraph
Selection.TypeText Text:="Adj: "
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="Adj"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
ActiveDocument.FormFields("ClaimantName").Select
Selection.Copy
If ActiveDocument.Bookmarks.Exists("Name") = True Then
ActiveDocument.Bookmarks("Name").Select
Selection.PasteSpecial DataType:=wdPasteText
Else
End If
ActiveDocument.FormFields("ClaimantSSN").Select
Selection.Copy
If ActiveDocument.Bookmarks.Exists("SSN") = True Then
ActiveDocument.Bookmarks("SSN").Select
Selection.PasteSpecial DataType:=wdPasteText
Else
End If
ActiveDocument.FormFields("ClaimantADJ").Select
Selection.Copy
If ActiveDocument.Bookmarks.Exists("Adj") = True Then
ActiveDocument.Bookmarks("Adj").Select
Selection.PasteSpecial DataType:=wdPasteText
Else
End If
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
As I said, I'm just curious why the run-time comes up. I realize object
programming and setting a range is probably more effective, tighter and
neater, I just haven't been able to get that approach to produce the desired
results.
Thanks!
"Michael" <mp...@connexus.net.au> wrote in message
news:Ow$ywPZCBHA.1784@tkmsftngp02...
Not only is going into the Headers/Footers cumbersome, but it also causes
the problem you're reporting, if the window is too small.
The best way to update the Header is like this:
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
.Range.Text = "Claimant Name: " & vbCr & "Social Security Number: " _
& vbCr & "Adj: "
End With
With regard to the rest of your code, I'm confused about several things:
1) Why are you creating the entire header through code rather than create it
in your template at design time, which is how this sort of thing is usually
done?
2) Why are you using paste link, rather than using a REF field, which again,
is how it's usually done - e.g.:
{ Ref "ClaimantName" \* CharFormat }
3) Why the need for the bookmarks in the Header? You can just refer to the
paragraph numbers in any subsequent macro, e,g.
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Paragraphs(3).Range.InsertAfter "Hello World"
Regards
Dave
"Steve Z" <szu...@govmail.state.nv.us> wrote in message
news:#YWi2uhCBHA.1480@tkmsftngp05...
Thanks for the info, I'll work with the tidbits you passed on and see if I
can make this a much better macro. Thanks again!
"Dave Rado" <dr...@onetel.net.uk> wrote in message
news:#vjaWJtCBHA.2080@tkmsftngp07...
If you get any spare time, it's also well worth looking though tha artcles
in the Macros/VBA tab of http://www.mvps.org/word/FAQs/.
Regards
Dave
"Steve Z" <szu...@govmail.state.nv.us> wrote in message
news:ODz1AnvCBHA.1536@tkmsftngp07...
Some of us have no formal training either. And sometimes it shows.
One good rule of thumb when you're trying to write code that's 'over
your head' is this: If, when you try recording it, you get monstrous
amounts of code to do what you think should be a simple task, and
especially if contains copious use of the Selection object, it's
usually something that can be coded much more simply with a totally
different approach that the recorder, by its very nature, can't
duplicate. Often this just involves using Ranges, or even (as in
parts of this case, evidently), just tweaking the template itself,
without using macros at all.
-- Mark Tangard <mtan...@speakeasy.net> ----------------------------
------ WWW: http://www.speakeasy.org/~mtangard ----------------------
------------- "Life is nothing if you aren't obsessed." --John Waters
---------------------------------------------------------------------