Please help, this routine will work the first time it is
run, the 2nd time it will fail at the first "Selection."
statment with the error Run-time error '91' Object
variable or With block variable not set. What have I done
wrong?
Another error message I sometimes get is Run-time error '462' The remote server machine does not exist or is unavailable
Option Compare Database
Public Const DocsMail As String = "C:\DocsMail\"
Public Const WordDot As String = "c:\Test.dot"
Public Const WordDot2 As String = "c:\Test2.dot"
Public strName As String
Public strMail As String
Public strType As String
Public docType1 As Word.Document
Public docType2 As Word.Document
Sub Start_Proc()
strMail = "c:\test1.doc"
strName = "data to insert"
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application"
Set docType1 = objWord.Documents.Open(WordDot, , ReadOnly)
Set docType2 = objWord.Documents.Open(WordDot2, , ReadOnly)
docType1.Select
'objWord.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory '## Edit template ##
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=strName
Selection.EndKey Unit:=wdStory
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=strName
Selection.HomeKey Unit:=wdLine
Selection.MoveUp Unit:=wdLine, Count:=5
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=strName
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCell, Count:=2
Selection.HomeKey Unit:=wdLine
'objWord.ScreenUpdating = True
ActiveDocument.SaveAs strMail
ActiveDocument.Close (wdDoNotSaveChanges)
Set docType1 = Nothing
Set docType2 = Nothing
objWord.Quit
Set objWord = Nothing
End Sub
run, the 2nd time it will fail at the first "Selection."
statment with the error Run-time error '91' Object
variable or With block variable not set. What have I done
wrong?
Another error message I sometimes get is Run-time error '462' The remote server machine does not exist or is unavailable
Option Compare Database
Public Const DocsMail As String = "C:\DocsMail\"
Public Const WordDot As String = "c:\Test.dot"
Public Const WordDot2 As String = "c:\Test2.dot"
Public strName As String
Public strMail As String
Public strType As String
Public docType1 As Word.Document
Public docType2 As Word.Document
Sub Start_Proc()
strMail = "c:\test1.doc"
strName = "data to insert"
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application"
Set docType1 = objWord.Documents.Open(WordDot, , ReadOnly)
Set docType2 = objWord.Documents.Open(WordDot2, , ReadOnly)
docType1.Select
'objWord.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory '## Edit template ##
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=strName
Selection.EndKey Unit:=wdStory
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=strName
Selection.HomeKey Unit:=wdLine
Selection.MoveUp Unit:=wdLine, Count:=5
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=strName
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCell, Count:=2
Selection.HomeKey Unit:=wdLine
'objWord.ScreenUpdating = True
ActiveDocument.SaveAs strMail
ActiveDocument.Close (wdDoNotSaveChanges)
Set docType1 = Nothing
Set docType2 = Nothing
objWord.Quit
Set objWord = Nothing
End Sub