ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1734|回复: 0

[原创] 测试 Visio 区段、行、列的最大许可号

[复制链接]

TA的精华主题

TA的得分主题

发表于 2014-5-30 11:50 | 显示全部楼层 |阅读模式
本帖最后由 uhnmki 于 2014-5-30 16:25 编辑

这是个副产品。Visio 帮助中没提到上限是多少(下限它说的也不对),就用试探的方法,试试上限到底是多少。
运行环境:WinXPsp3 + OfficeXP + Visio 2002。
先手动试,注意,一定要事先选择一个图形,才能使用程序,


  1. '方法一、手动调 S、R、C ,如发生:运行时错误 '-2032465765 (86db089b)': 不能创建对象。则下调 S、R、C 数值。由高位数万、千、……一直试到个位。
  2. Sub Exploring_MaxNum_Index_Of_Sec_Row_Col_v01()
  3.     Dim shpObj As Shape
  4.     Set shpObj = ActiveWindow.Selection(1)
  5. Manually_Tunning:
  6.     Dim shpcelObj As Cell
  7.     Set shpcelObj = shpObj.CellsSRC(254, 32767, 254)    '可调节 S、R、C Index 试错
  8.     Dim fExistsLocally As Boolean
  9.     fExistsLocally = True
  10. Debug_Print:
  11.     With shpcelObj
  12.         Debug.Print "------- test_valid_secIndex_rowIndex_colIndex -------"
  13.         Debug.Print "CellsSRC("; .Section; ","; .Row; ","; .Column; ")"; ".Name : "; .Name
  14.         Debug.Print Tab(17); ".IsInherited : "; CBool(.IsInherited)
  15.         Debug.Print "Shape.CellsSRCExists("; .Section; ","; .Row; ","; .Column; ","; fExistsLocally; ") = "; CBool(shpObj.CellsSRCExists(.Section, .Row, .Column, fExistsLocally))
  16.     End With
  17. End Sub

复制代码
得到:MaxSecNum: 254   ;  MaxRowNum: 32767    ;   MaxColNum: 254。
手动的太累,弄点高大上的,于是:

  1. '方法二、自动找寻 S、R、C 上限,DO……Loop 循环,一直到运行时错,记下循环数。
  2. Sub Exploring_MaxNum_Index_Of_Sec_Row_Col_v02()
  3.     Dim secIndex As Long, rowIndex As Long, colIndex As Long
  4. AutoExploring_1:    '都记录到 cellName 变量中,但太大死机,根本运行不下去,宕机,弃之
  5.     secIndex = 1
  6.     rowIndex = 1
  7.     colIndex = 0
  8.    
  9.     Dim shpObj As Shape
  10.     Set shpObj = ActiveWindow.Selection(1)
  11.     Dim testStr As String
  12.     Dim CellName As String
  13. With shpObj
  14. On Error Resume Next
  15.     Do    '寻找 column Index 最大值
  16.         testStr = .CellsSRC(secIndex, rowIndex, colIndex).Name
  17.         If Err.Number = 0 Then
  18.             CellName = "CellsSRC(" & secIndex & "," & rowIndex & "," & colIndex & ").Name: " & .CellsSRC(secIndex, rowIndex, colIndex).Name & vbCrLf
  19.             colIndex = colIndex + 1
  20.         Else
  21.             Err.Clear
  22.             LoopOver = True
  23.             MaxCol = colIndex - 1
  24.             colIndex = colIndex - 1
  25.         End If
  26.     Loop Until LoopOver = True
  27.     LoopOver = False
  28.    
  29.     Do    '寻找 row Index 最大值
  30.         testStr = .CellsSRC(secIndex, rowIndex, colIndex).Name
  31.         If Err.Number = 0 Then
  32.             CellName = "CellsSRC(" & secIndex & "," & rowIndex & "," & colIndex & ").Name" & .CellsSRC(secIndex, rowIndex, colIndex).Name & vbCrLf
  33.             rowIndex = rowIndex + 1
  34.         Else
  35.             Err.Clear
  36.             LoopOver = True
  37.             MaxRow = rowIndex - 1
  38.             rowIndex = rowIndex - 1
  39.         End If
  40.     Loop Until LoopOver = True
  41.     LoopOver = False
  42.    
  43.     Do    '寻找 section Index 最大值
  44.         testStr = .CellsSRC(secIndex, rowIndex, colIndex).Name
  45.         If Err.Number = 0 Then
  46.             CellName = "CellsSRC(" & secIndex & "," & rowIndex & "," & colIndex & ").Name" & .CellsSRC(secIndex, rowIndex, colIndex).Name & vbCrLf
  47.             secIndex = secIndex + 1
  48.         Else
  49.             Err.Clear
  50.             LoopOver = True
  51.             MaxSec = secIndex - 1
  52.             secIndex = secIndex - 1
  53.         End If
  54.     Loop Until LoopOver = True
  55. On Error GoTo 0
  56.    
  57.     '输出到文本文件,与Visio文档同名的.txt
  58.     Open StrReverse(Replace(StrReverse(ThisDocument.Path & ThisDocument.Name), ".", "_", Count:=1)) & ".txt" For Output As #2
  59.     Print #2, CellName
  60.     Print #2, "Max Section Number:"; MaxSec; Tab(28); "Max Row Number:"; MaxRow; Tab(50); "Max Column Number:"; MaxCol
  61. End With
  62.    
  63.     Close #2
  64. End Sub
复制代码
附件为 ver 0.3 版的作法。
调查Visio区段号、行号、列号的最大可取值.zip (351.38 KB, 下载次数: 4)

天可怜见,给点分啦、鲜花啦、掌声啦,能换点权、利的都行,请不吝赐之,多多益善。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-28 09:23 , Processed in 0.032384 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表