Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automation Error

Status
Not open for further replies.

LJtechnical

Technical User
Aug 7, 2002
90
0
0
GB
I have a button that should open a word template and continue with the vb code embedded in the template. Occasionally it works but for some reason I am getting Automation errors, I am lost as to why! Any Ideas?

Private Sub Command42_Click()
On Error GoTo Err_Command42_Click

Dim wrdApp As Object
Dim strFileNm As String
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
With FileSearch
Do

.NewSearch
strFileNm = "Mapimport"
.MatchTextExactly = True
.LookIn = "C:\Program Files\Microsoft Office\Templates"
.SearchSubFolders = False
.Filename = Dir(strFileNm)
.Execute
Loop While .FoundFiles.Count = 0
End With

Documents.Add Template:="C:\Program Files\Microsoft Office" _
& "\Templates\Mapimport.dot"

Exit_Command42_Click:
Exit Sub

Err_Command42_Click:
MsgBox Err.Description
Resume Exit_Command42_Click

End Sub
 
Maybe knowledge base article Q199219 on the microsoft website will help. I ran across it in search of help with another problem, and it looks like it is related to your problem. The article describes problems using the With statement.

-Larissalle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top