Foxtable(狐表)用户栏目专家坐堂 → excel文件循环对象文本框识别


  共有1277人关注过本帖树形打印复制链接

主题:excel文件循环对象文本框识别

帅哥哟,离线,有人找我吗?
azlm100
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:18 积分:271 威望:0 精华:0 注册:2019/8/7 15:51:00
excel文件循环对象文本框识别  发帖心情 Post By:2023/8/24 13:24:00 [只看该作者]

打开一份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
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:18 积分:271 威望:0 精华:0 注册:2019/8/7 15:51:00
  发帖心情 Post By: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

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106209 积分:540168 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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)

 回到顶部