Я искал везде и не мог найти ответ.
dim str as string, d as string
str = "abc copy ABCD EFGH IJKL MNOP QRST UVWX YZ copy def"
d = "copy"
Используйте вложенные функции InStr для определения местоположения начальной и конечной точек.
str = mid$(str, instr(1, str, d, vbtextcompare)+len(d)))
str = trim$(left$(str , instr(1, str, d, vbtextcompare) - 1))
debug.print str
Используйте copy в качестве разделителя для разделения.
str = trim$(split(split(str, d)(1), d)(0))
'*copy* is used for both start and stop; the above could be
str = trim$(split(str, d)(1))
debug.print str
Используйте регулярные выражения для извлечения подстроки.
dim rgx as object
set rgx = createobject("vbscript.regexp")
with rgx
.global = False
.ignorecase = True
.multiline = False
.pattern = d & " (.*?)(?= " & d & ")"
if .test(str) then
str = mid$(.execute(str)(0), 6)
debug.print str
End If
end with
Использованиефункции листа для анализа подстроки.
with application.worksheetfunction
str = .replace(str, 1, .search(d, str) + len(d), vbnullstring)
str = trim(.replace(str, .search(d, str), len(str), vbnullstring))
debug.print str
end with
'alternate
with application.worksheetfunction
str = trim(mid$(.substitute(str, d, space(len(str))), len(str), len(str)))
debug.print str
end with
Так что, похоже, вы действительно не так уж и тяжело выглядели.