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
///////////////////////////////////
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
///////////////////////////////////