Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
type mismatch [email protected] Excel Programming 10 August 15th 08 08:04 PM
Type Mismatch: array or user defined type expected ExcelMonkey Excel Programming 4 July 6th 06 03:40 PM
Type mismatch using rnge as Range with Type 8 Input Box STEVE BELL Excel Programming 11 December 3rd 05 05:02 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
type mismatch--how to fix rroach Excel Discussion (Misc queries) 2 July 14th 05 06:23 PM


All times are GMT +1. The time now is 09:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"