即使指定的Spring在string中发生,Excel中的InStr函数也会返回0

我正在处理string,并获取一些我需要在Excel中复制的字符。 它工作得很好,但是当我的Windows PC需要重新启动更新并打开它时,代码不再工作。 我不知道这是否与被禁用的macros有关,或者我需要configuration一些东西。 真的需要帮助,因为它是如此累人手动粘贴细胞逐个细胞。

Sub appendDetails() Dim jobs As String Dim CommandLine As String 'Helper Variables Dim x As Integer Dim y As Integer Dim z As Integer 'Gets all the job description jobs = Cells(2, "B").Value If (jobs <> "") Then 'Get CommandLine My issue is InStr(jobs, "Command Line : ") is returning 0 when in fact "Command Line : " keyword appears inside job string If (InStr(jobs, "Command Line : ") = 0) Then ActiveCell.Value = "" ActiveCell.Offset(0, 1).Activate Else x = getPosition(jobs, "Command Line : ") + thisPosition("Command Line : ") y = getPosition(jobs, "Host/Host Group : ") z = getLengthOfString(x, y) CommandLine = getString(jobs, x, z) ActiveCell.Value = Trim(Replace(CommandLine, Chr(10), "")) ActiveCell.Offset(0, 1).Activate MsgBox ("Command Line : " + CommandLine) End If End Sub 

澄清,这个子函数调用我没有包括在这里的其他函数。 就好像你对function很好奇。

这是你在我之前发表的评论中的答案

InStr返回0,因为指定的子string不在string中发生。 使用debug.print来检查你的值