{"id":8140,"date":"2021-11-26T12:15:02","date_gmt":"2021-11-26T12:15:02","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=8140"},"modified":"2021-11-26T12:16:21","modified_gmt":"2021-11-26T12:16:21","slug":"run-time-error-13-type-mismatch","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/office\/runtime-error-13-type-mismatch\/15706.html","title":{"rendered":"Run-Time Error 13 &#8211; Type Mismatch"},"content":{"rendered":"<p>Hi,<\/p>\n<p>I had a VB script in Excel 2010 working but for some reason it has become curropt and i&#8217;m getting the run-time 13 error message.<\/p>\n<p>I have pasted the script below.<\/p>\n<p>Please can you help?<\/p>\n<p>Option Explicit<\/p>\n<p>Private Sub Workbook_Open()<br \/>\nDim objExcel<br \/>\nDim objWorkbook<br \/>\nDim rngStart<br \/>\nDim rngEnd<br \/>\nDim rngCell<br \/>\nDim strHtmlHead<br \/>\nDim strHtmlFoot<br \/>\nDim strMsgBody<br \/>\nDim strMsg<br \/>\nDim sFilename<br \/>\nDim sPath<br \/>\nDim oApp As Object<br \/>\nDim oMail As Object<br \/>\nDim Mailid As String<\/p>\n<p>Set objExcel = CreateObject(&#8220;Excel.Application&#8221;)<\/p>\n<p>&#8216;open Workbook<br \/>\nobjExcel.Workbooks.Open (&#8220;C:\\Tracking.xlsx&#8221;)<\/p>\n<p>&#8216;setup basic HTML message header and footer<br \/>\nstrHtmlHead = &#8220;&lt;html&gt;&lt;body&gt;&#8221;<br \/>\nstrHtmlFoot = &#8220;&lt;\/body&gt;&lt;\/html&gt;&#8221;<\/p>\n<p>&#8216;setup start of body of message<br \/>\nstrMsgBody = &#8220;The following Item(s) are recently overdue or are due to be returned in less than 3 days&lt;p \/&gt;&#8221;<\/p>\n<p>&#8216;Worksheet name<br \/>\nWith objExcel.Workbooks(&#8220;Tracking.xlsx&#8221;).Worksheets(&#8220;Inventory&#8221;)<br \/>\n&#8216;set start of date range<br \/>\nSet rngStart = .Range(&#8220;E2&#8221;)<br \/>\n&#8216;find end of date range<br \/>\nSet rngEnd = .Range(&#8220;E&#8221; &amp; CStr(objExcel.Application.Rows.Count)).End(-4162)<\/p>\n<p>&#8216;loop through all used cells in column E<br \/>\nFor Each rngCell In .Range(rngStart, rngEnd)<br \/>\n&#8216;if date is less than 1 day from today and not more than 3 days in the future then add data to message<br \/>\n&#8216;THE BELOW LINE IS THE HIGHLIGHTED LINE WITH THE ERROR<br \/>\nIf (rngCell.Value &#8211; Int(Date) &gt;= -1 And Not rngCell.Value &#8211; Int(Date) &gt;= 3) Then<br \/>\n&#8216;add to message &#8211; use Item name from column B (offset -3)<br \/>\n&#8216;add to message &#8211; use Loaned To name from column D (offset -1)<br \/>\n&#8216;add to message &#8211; use Ststus name from column F (offset 1)<br \/>\nstrMsgBody = strMsgBody &amp; &#8220;Item: &#8221; &amp; rngCell.Offset(0, -3).Text &amp; &#8221; Loaned To: &#8221; &amp; rngCell.Offset(0, -1).Text &amp; &#8221; is due on: &#8221; &amp; rngCell.Text &amp; &#8221; &#8212; Status &#8221; &amp; rngCell.Offset(0, 1).Text &amp; &#8220;&lt;br \/&gt;&#8221;<br \/>\nEnd If<br \/>\nNext<\/p>\n<p>&#8216;Note last reminder time\/date in column A<br \/>\nrngEnd.Offset(1, -4) = Now<br \/>\nrngEnd.Offset(1, -4).NumberFormat = &#8220;dd\/mm\/yy \\a\\t hh:mm&#8221;<br \/>\nEnd With<\/p>\n<p>&#8216;put message together<br \/>\nstrMsg = strHtmlHead &amp; strMsgBody &amp; strHtmlFoot<\/p>\n<p>&#8216;Define email id here<br \/>\nMailid = &#8220;helpdesk@hotmail.co.uk&#8221;<\/p>\n<p>&#8216;create the e-mail object<br \/>\nSet oApp = CreateObject(&#8220;Outlook.Application&#8221;)<br \/>\nSet oMail = oApp.CreateItem(0)<br \/>\nWith oMail<br \/>\n.To = Mailid<br \/>\n.Subject = &#8220;Loan Equipment&#8221;<br \/>\n.HtmlBody = strMsg<br \/>\n.send<br \/>\nEnd With<\/p>\n<p>&#8216;remove the e-mail object<br \/>\nSet oMail = Nothing<br \/>\nSet oApp = Nothing<\/p>\n<p>&#8216;close workbook<br \/>\nobjExcel.Workbooks(&#8220;Tracking.xlsx&#8221;).Close (True)<\/p>\n<p>&#8216;remove the Excel object<br \/>\nobjExcel.Quit<br \/>\nEnd Sub<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":2},"question-category":[53],"question_tags":[],"class_list":["post-8140","question","type-question","status-publish","hentry","question-category-office"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/8140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=8140"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=8140"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=8140"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=8140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}