Error No 5; Description: Invalid Procedure call or argument

toleafs

Active Member
Joined
Jun 27, 2005
Messages
498
Hello
Does anyone know why I am getting the error message?
Thanks in advance for your help
------------------
Private Sub cmdWordLetter_Click()

On Error GoTo ErrorHandler

Dim appWord As Word.Application
Dim docs As Word.Documents
Dim strLetter As String
Dim prps As Object
Dim strDate As String
Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File
Dim strTemplate As String
Dim strTemplatePath As String
Dim strTemplateNameAndPath As String
Dim doc As Word.Document
Dim strTitle As String
Dim strPrompt As String

strDate = CStr(Date)
'Check whether template is found in the folder
'Get User Templates path from Word Options dialog
'(or replace with hard-coded path for your computer)
Set appWord = GetObject(, "Word.Application")
'strTemplatePath = appWord.Options.DefaultFilePath(wdUserTemplatesPath)
'Debug.Print "Template path: " & strTemplatePath
strTemplatePath = strTemplatePath & "S:\NonCon\Business_Analytics\Andrea_Palermo\"
strLetter = "DocDE.dot"
strTemplateNameAndPath = strTemplatePath & strLetter
Debug.Print "Template and path: " & strTemplateNameAndPath

On Error Resume Next

Set fil = fso.GetFile(strTemplateNameAndPath)
If fil Is Nothing Then
strPrompt = "Can't find " & strLetter & " in " _
& strTemplatePath & "; canceling"
MsgBox strPrompt, vbCritical + vbOKOnly
GoTo ErrorHandlerExit
End If

On Error GoTo ErrorHandler

Set docs = appWord.Documents
Set doc = docs.Add(strTemplateNameAndPath)

Set prps = doc.CustomDocumentProperties

With prps
.Item("DEC").Value = Nz(Me![strDEC])
.Item("DATAELEMENT").Value = Nz(Me![strDEs])
.Item("DATAELEMENTSTATUS").Value = Nz(Me![strDEP])
.Item("SIGNOFF").Value = Nz(Me![strSignoff])
.Item("DESCRIPTION").Value = Nz(Me![strDesc])

End With

With appWord
.Visible = True
.Activate
.Selection.WholeStory
.Selection.Fields.Update
.Selection.MoveDown Unit:=wdLine, Count:=1
End With

ErrorHandlerExit:
Exit Sub

ErrorHandler:
If Err = 429 Then
'Word is not running; open Word with CreateObject
Set appWord = CreateObject("Word.Application")
Resume Next
Else
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End If
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Have you tried stepping thru the code to see where the error occurs?
 
Upvote 0
Which line of code is highlighted when you get the error?
 
Upvote 0
When you get that error message, are you given the choice of a "Debug" button?
If so, click it. It should highlight the offending code line in yellow.
 
Upvote 0
Remove everything starting with On Error... and goto Tools>Options...General tab, select Break On All Errors.

Now do you get anything highlighted when you run the code?

PS I would take a guess where the error is but there's actually a few candidates, with none sticking out in particular.
 
Upvote 0
Do you get any output from your debug.print? Do you receive any MsgBox output?


You could put a breakpoint on this line

strDate = CStr(Date)

then execute your application.

When the procedure stops on the line with the break point,
hit F8 and it will proceed with the next line,
repeat this until you get the error

the line that results in the error is the problem area.
 
Upvote 0
is this the name of the event handler attached to a button ?
cmdWordLetter_Click

maybe what's actually attached is different than what you've typed

maybe what's attached is cmdWordLettter_Click <-mispelled with 3 t's

so when you click on the button its trying to run a procedure that it can't find
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top