ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Type Mismatch (13) (https://www.excelbanter.com/excel-programming/426051-type-mismatch-13-a.html)

Alan[_8_]

Type Mismatch (13)
 
The code below is giving me a runtime error 13 (type mismatch), but
I cannot figure out why. It is failing on this line:

sPDFName = Replace(sWordName, pos, 4, ".pdf")

but it appears to use the right syntax. This was tested with an input
of WordDocPath = "test.doc"

Alan

Sub ProcessWord (WordDocPath As String)

Dim sPDFName As String, sPDFPath As String
Dim pos As Integer, sWordName As String

sWordName = WordDocPath
pos = InStr(1, sWordName, ".doc")
If (pos = 0) Then
DisplayErrorMessage (sWordName & " is not a Word document")
Exit Sub
Else
sPDFName = Replace(sWordName, pos, 4, ".pdf")
End If

Jacob Skaria

Type Mismatch (13)
 
Dear Alan

sPDFName = Replace(sWordName, pos, 4, ".pdf")

In the above code 'pos' should be a string variable. The syntax for Replace
is (expression, find, replace[, start[, count[, compare]]]) where expression
and find are string variables. In your code pos is a integer which returns a
type mismatch error.


If this post helps click Yes
---------------
Jacob Skaria


"Alan" wrote:

The code below is giving me a runtime error 13 (type mismatch), but
I cannot figure out why. It is failing on this line:

sPDFName = Replace(sWordName, pos, 4, ".pdf")

but it appears to use the right syntax. This was tested with an input
of WordDocPath = "test.doc"

Alan

Sub ProcessWord (WordDocPath As String)

Dim sPDFName As String, sPDFPath As String
Dim pos As Integer, sWordName As String

sWordName = WordDocPath
pos = InStr(1, sWordName, ".doc")
If (pos = 0) Then
DisplayErrorMessage (sWordName & " is not a Word document")
Exit Sub
Else
sPDFName = Replace(sWordName, pos, 4, ".pdf")
End If


Jacob Skaria

Type Mismatch (13)
 
Dear Alan

sPDFName = Replace(sWordName, pos, 4, ".pdf")

In the above code variable 'pos' should be a string. The syntax for Replace
is
Replace(expression, find, replace[, start[, count[, compare]]]) where
'expression' and 'find' are string functions. Replace 'pos' with the
substring being searched for.

Eg: Replace("abcd","b","c") = "accd"

If this post helps click Yes
---------------
Jacob Skaria


"Alan" wrote:

The code below is giving me a runtime error 13 (type mismatch), but
I cannot figure out why. It is failing on this line:

sPDFName = Replace(sWordName, pos, 4, ".pdf")

but it appears to use the right syntax. This was tested with an input
of WordDocPath = "test.doc"

Alan

Sub ProcessWord (WordDocPath As String)

Dim sPDFName As String, sPDFPath As String
Dim pos As Integer, sWordName As String

sWordName = WordDocPath
pos = InStr(1, sWordName, ".doc")
If (pos = 0) Then
DisplayErrorMessage (sWordName & " is not a Word document")
Exit Sub
Else
sPDFName = Replace(sWordName, pos, 4, ".pdf")
End If



All times are GMT +1. The time now is 10:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com