5149: the measurement must be between 1584 and -1584

M

mskinner

Hi All,

The error message is coming up when a macro is run on word 2003 on XP
Professional.Works fine on some machines and failes on others with the
same configuration.

the macro is:

Any ideas?

I have marked the error with : the error is here!!!!!!!!!!!!!!!!!


Thanks

(e-mail address removed)


////////////////////////////////////


Sub SaveFiles()

'Defsgn A - Z
Dim li_top_margin As Single
Dim li_left_margin As Single
Dim li_right_margin As Single
Dim li_bottom_margin As Single

Set fs = CreateObject("Scripting.FileSystemObject")
If Not fs.FolderExists("c:\intellicred\fax\") Then
MsgBox ("The folder c:\intellicred\fax\ does not exist. This
must be created")
Exit Sub
End If

ChangeFileOpenDirectory "C:\intellicred\fax\"

ActiveDocument.SaveAs FileName:="main.doc"

li_top_margin = ActiveDocument.PageSetup.TopMargin
li_bottom_margin = ActiveDocument.PageSetup.BottomMargin
li_left_margin = ActiveDocument.PageSetup.LeftMargin
li_right_margin = ActiveDocument.PageSetup.RightMargin

With ActiveDocument.MailMerge
.DataSource.FirstRecord = 1
.DataSource.LastRecord = 100000
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute
End With

Documents(1).Activate
ActiveDocument.SaveAs FileName:="mergeddoc.doc"

Documents("main.doc").Activate

ActiveDocument.Repaginate
li_main_doc_page_cnt =
ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
Documents("mergeddoc.doc").Activate

'Used to set criteria for moving through the document by page
Application.Browser.Target = wdBrowsePage
ActiveDocument.Repaginate

'get the number of pages in the mergedoc
li_merge_doc_pages =
ActiveDocument.BuiltInDocumentProperties("Number of Pages")


p = 0
For i = 1 To li_merge_doc_pages
p = p + 1
'For p = 1 To li_main_doc_page_cnt
'go to the MERGE TO document
'Select and copy the text to the clipboard
ActiveDocument.Bookmarks("\page").Range.Copy
If p = 1 Then
DocNum = DocNum + 1
ls_new_doc_name = "fax_" & DocNum & ".doc"
Documents.Add
ActiveDocument.SaveAs FileName:="fax_" & DocNum & ".doc"
ActiveDocument.PageSetup.TopMargin = li_top_margin /// the
error is here!!!!!!!!!!!!!!!!!!!!
ActiveDocument.PageSetup.BottomMargin = li_bottom_margin
ActiveDocument.PageSetup.LeftMargin = li_left_margin
ActiveDocument.PageSetup.RightMargin = li_right_margin

'set margins
'With Documents("fax_" & DocNum & ".doc").PageSetup
' .LeftMargin = InchesToPoints(li_left_margin)
' .RightMargin = InchesToPoints(li_right_margin)
' .TopMargin = InchesToPoints(li_top_margin)
'.BottomMargin = InchesToPoints(li_bottom_margin)
'End With

End If
'Open new document to paste the content of the clipboard into.
Documents(ls_new_doc_name).Activate
Selection.Paste
If p = li_main_doc_page_cnt Then
'Removes the break that is copied at the end of the page,
if any.
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1

ActiveDocument.Repaginate
If ActiveDocument.BuiltInDocumentProperties("Number of
Pages") > p Then
Selection.TypeBackspace
End If
End If

If p = li_main_doc_page_cnt Then
Documents(ls_new_doc_name).Activate
ActiveDocument.Save
ActiveDocument.Close
'Move the selection to the next page in the document
Documents("mergeddoc.doc").Activate
p = 0
End If

Documents("mergeddoc.doc").Activate
Application.Browser.Next

'Next p

Next i

Documents("mergeddoc.doc").Activate
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Documents("main.doc").Activate
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Application.Quit _

End Sub




///////////////////////////////////
 
J

Jonathan West

I suspect that what is happening is that in some documents, you have
multiple sections and not all the sections have the same margins. In such
circumstances, the value returned by any of the margin properties of the
ActiveDocument is 9999999, the value of the wdUndefined constant.

What I suggest is that instead of reading the margin properties from the
ActiveDocument.PageSetup object, you read them from
ActiveDocument.Sections(1).PageSetup. This way, you can avoid the
possibility of getting a wdUndefined value.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
W

Word Heretic

G'day "mskinner" <[email protected]>,

Your document has multiple sections. By reading the generic page
layout the top margin has been reported as wdUndefined because there
is a difference in it between sections.

Set your margin variables to

ActiveDocument.Sections(1).Page....



Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


mskinner reckoned:
 

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