L
Laurie C
I am trying to create a VB script that runs a mail merge and then saves the
destination file. However, the script crashes every time with a dialog box
that says "Word cannot complete the save due to a file permission error."
I suspect some kind of file lock problem, as this is my own computer and I
am the administrator (the only user, period), so I wouldn't think that file
permissions could really be the problem.
Sometimes I get a similar error when trying to save the destination file
when I run the merge manually and try to save the file. (The wording is a
little different, but same result - sorry I didn't write it down.)
My script is below. Any help would be appreciated.
Laurie C
Option Explicit
Dim fs, rpt, objWord
Set fs = CreateObject("Scripting.FileSystemObject")
Set objWord = CreateObject("Word.Application")
objWord.documents.open("F1.DOT")
objWord.ActiveDocument.MailMerge.OpenDataSource("025139.doc")
With objWord.ActiveDocument.MailMerge
.Destination = 0 'wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 1 'wdDefaultFirstRecord
.LastRecord = -16 'wdDefaultLastRecord
End With
.Execute (false) ' (pause = false)
End With
Call objWord.ActiveDocument.SaveAs ("testtest.DOC")
objWord.ActiveDocument.Password = "password"
Call objWord.ActiveDocument.Save()
objWord.ActiveDocument.Close()
objWord.ActiveDocument.Close()
objWord.Quit
set objWord = Nothing
Set fs = Nothing
destination file. However, the script crashes every time with a dialog box
that says "Word cannot complete the save due to a file permission error."
I suspect some kind of file lock problem, as this is my own computer and I
am the administrator (the only user, period), so I wouldn't think that file
permissions could really be the problem.
Sometimes I get a similar error when trying to save the destination file
when I run the merge manually and try to save the file. (The wording is a
little different, but same result - sorry I didn't write it down.)
My script is below. Any help would be appreciated.
Laurie C
Option Explicit
Dim fs, rpt, objWord
Set fs = CreateObject("Scripting.FileSystemObject")
Set objWord = CreateObject("Word.Application")
objWord.documents.open("F1.DOT")
objWord.ActiveDocument.MailMerge.OpenDataSource("025139.doc")
With objWord.ActiveDocument.MailMerge
.Destination = 0 'wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 1 'wdDefaultFirstRecord
.LastRecord = -16 'wdDefaultLastRecord
End With
.Execute (false) ' (pause = false)
End With
Call objWord.ActiveDocument.SaveAs ("testtest.DOC")
objWord.ActiveDocument.Password = "password"
Call objWord.ActiveDocument.Save()
objWord.ActiveDocument.Close()
objWord.ActiveDocument.Close()
objWord.Quit
set objWord = Nothing
Set fs = Nothing