以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  excel文件循环对象文本框识别  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=187972)

--  作者:azlm100
--  发布时间:2023/8/24 13:24:00
--  excel文件循环对象文本框识别
打开一份excel文件,然后循环所有对象。再获取对象内的文本信息进行处理。
 For Each shp In sheet.Shapes
                Dim sin As Single
                Dim d As Date
                If Single.TryParse(shp.TextFrame.Characters.Text,sin) = False Then
                    If Date.TryParse(shp.TextFrame.Characters.Text,d) = False Then
                        Dim str As String = (shp.TextFrame.Characters.Text)
                        If  shp.TextFrame.Characters.Text <> "" Then
                            If str.Length > 1 Then
     end if
end if
            end if
end if
next

现在有一个问题就是循环对象的时候如果有一个对象是图片或者表格之类的,就会报错。
所以想在循环的时候识别是否为文本框对象。
查了excel的vb语言有这样一句
For Each shp In sheet.Shapes
If shp.ShapeType = msoTextbox Then
\' 处理文本框的代码
End If
Next shp

但是贴到foxtable里会提示未声明msoTextbox

想问下有什么语句可以在循环对象时候的识别出是否为文本框。

求助

--  作者:azlm100
--  发布时间:2023/8/24 15:34:00
--  
没事了,解决了。加了一个错误判断

 For Each shp In sheet.Shapes
                Dim sin As Single
                Dim d As Date
try
                If Single.TryParse(shp.TextFrame.Characters.Text,sin) = False Then
                    If Date.TryParse(shp.TextFrame.Characters.Text,d) = False Then
                        Dim str As String = (shp.TextFrame.Characters.Text)
                        If  shp.TextFrame.Characters.Text <> "" Then
                            If str.Length > 1 Then
     end if
end if
            end if
end if
next

--  作者:有点蓝
--  发布时间:2023/8/24 15:37:00
--  
If shp.Type = Microsoft.Office.Core.MsoShapeType.msoTextbox Then

https://learn.microsoft.com/zh-cn/previous-versions/office/developer/office-2010/ms251190(v=office.14)