|
楼主 |
发表于 2023-11-27 08:37
|
显示全部楼层
大佬,请你花宝贵的时间,帮我看看我的VSTO代码如何解决?
VBA代码已上传附件,我转换成VSTO代码如下。
VBA代码在EXCEL中运行是没有问题的。
VSTO代码感觉问题出在正则表达式提取循环语句。
vTmp参数,在VBA中调试,值是字符串;在VSTO中调试,值是Nothing。
Private Sub Button6_Click(sender As Object, e As RibbonControlEventArgs) Handles Button6.Click
Dim strAddress As String '定义选中单元格区域地址字符串
Dim strResult As String '定义选中单元格区域处理后(去掉字母)地址字符串
Dim varTmp '定义选中单元格区域处理后(去掉字母)地址字符串数组
Dim objRegExp
Dim vTmp
Dim intI, intJ As Integer '定义循环计数器
Dim intCount As Integer '定义选中单元格区域处理后地址字符串中的行标
With xlApp
'-------------------------------------------------------------------
'///////////////////////////////////////////////////////////////////
'处理选中单元区域地址字符串
'-------------------------------------------------------------------
strAddress = .Selection.Address
objRegExp = CreateObject("VbScript.RegExp")
objRegExp.Global = True
objRegExp.IgnoreCase = True
objRegExp.Pattern = "[\d.$\d]+"
strResult = ""
For Each vTmp In objRegExp.Execute(strAddress) '感觉这段循环语句有问题。
strResult = strResult & vTmp
Next
'-------------------------------------------------------------------
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'-------------------------------------------------------------------
varTmp = Split(strResult, "$$")
intCount = UBound(varTmp)
For intI = intCount / 2 To 1 Step -1
For intJ = varTmp(intI * 2) To varTmp(intI * 2 - 1) Step -1
.Rows(intJ + 1).Insert(Shift:=XlDirection.xlDown, CopyOrigin:=XlInsertFormatOrigin.xlFormatFromLeftOrAbove)
Next intJ
Next intI
End With
End Sub
再次谢谢大佬!!!!
|
|