|
本帖最后由 uhnmki 于 2014-5-30 16:25 编辑
这是个副产品。Visio 帮助中没提到上限是多少(下限它说的也不对),就用试探的方法,试试上限到底是多少。
运行环境:WinXPsp3 + OfficeXP + Visio 2002。
先手动试,注意,一定要事先选择一个图形,才能使用程序,
- '方法一、手动调 S、R、C ,如发生:运行时错误 '-2032465765 (86db089b)': 不能创建对象。则下调 S、R、C 数值。由高位数万、千、……一直试到个位。
- Sub Exploring_MaxNum_Index_Of_Sec_Row_Col_v01()
- Dim shpObj As Shape
- Set shpObj = ActiveWindow.Selection(1)
- Manually_Tunning:
- Dim shpcelObj As Cell
- Set shpcelObj = shpObj.CellsSRC(254, 32767, 254) '可调节 S、R、C Index 试错
- Dim fExistsLocally As Boolean
- fExistsLocally = True
- Debug_Print:
- With shpcelObj
- Debug.Print "------- test_valid_secIndex_rowIndex_colIndex -------"
- Debug.Print "CellsSRC("; .Section; ","; .Row; ","; .Column; ")"; ".Name : "; .Name
- Debug.Print Tab(17); ".IsInherited : "; CBool(.IsInherited)
- Debug.Print "Shape.CellsSRCExists("; .Section; ","; .Row; ","; .Column; ","; fExistsLocally; ") = "; CBool(shpObj.CellsSRCExists(.Section, .Row, .Column, fExistsLocally))
- End With
- End Sub
复制代码 得到:MaxSecNum: 254 ; MaxRowNum: 32767 ; MaxColNum: 254。
手动的太累,弄点高大上的,于是:
- '方法二、自动找寻 S、R、C 上限,DO……Loop 循环,一直到运行时错,记下循环数。
- Sub Exploring_MaxNum_Index_Of_Sec_Row_Col_v02()
- Dim secIndex As Long, rowIndex As Long, colIndex As Long
- AutoExploring_1: '都记录到 cellName 变量中,但太大死机,根本运行不下去,宕机,弃之
- secIndex = 1
- rowIndex = 1
- colIndex = 0
-
- Dim shpObj As Shape
- Set shpObj = ActiveWindow.Selection(1)
- Dim testStr As String
- Dim CellName As String
- With shpObj
- On Error Resume Next
- Do '寻找 column Index 最大值
- testStr = .CellsSRC(secIndex, rowIndex, colIndex).Name
- If Err.Number = 0 Then
- CellName = "CellsSRC(" & secIndex & "," & rowIndex & "," & colIndex & ").Name: " & .CellsSRC(secIndex, rowIndex, colIndex).Name & vbCrLf
- colIndex = colIndex + 1
- Else
- Err.Clear
- LoopOver = True
- MaxCol = colIndex - 1
- colIndex = colIndex - 1
- End If
- Loop Until LoopOver = True
- LoopOver = False
-
- Do '寻找 row Index 最大值
- testStr = .CellsSRC(secIndex, rowIndex, colIndex).Name
- If Err.Number = 0 Then
- CellName = "CellsSRC(" & secIndex & "," & rowIndex & "," & colIndex & ").Name" & .CellsSRC(secIndex, rowIndex, colIndex).Name & vbCrLf
- rowIndex = rowIndex + 1
- Else
- Err.Clear
- LoopOver = True
- MaxRow = rowIndex - 1
- rowIndex = rowIndex - 1
- End If
- Loop Until LoopOver = True
- LoopOver = False
-
- Do '寻找 section Index 最大值
- testStr = .CellsSRC(secIndex, rowIndex, colIndex).Name
- If Err.Number = 0 Then
- CellName = "CellsSRC(" & secIndex & "," & rowIndex & "," & colIndex & ").Name" & .CellsSRC(secIndex, rowIndex, colIndex).Name & vbCrLf
- secIndex = secIndex + 1
- Else
- Err.Clear
- LoopOver = True
- MaxSec = secIndex - 1
- secIndex = secIndex - 1
- End If
- Loop Until LoopOver = True
- On Error GoTo 0
-
- '输出到文本文件,与Visio文档同名的.txt
- Open StrReverse(Replace(StrReverse(ThisDocument.Path & ThisDocument.Name), ".", "_", Count:=1)) & ".txt" For Output As #2
- Print #2, CellName
- Print #2, "Max Section Number:"; MaxSec; Tab(28); "Max Row Number:"; MaxRow; Tab(50); "Max Column Number:"; MaxCol
- End With
-
- Close #2
- End Sub
复制代码 附件为 ver 0.3 版的作法。
调查Visio区段号、行号、列号的最大可取值.zip
(351.38 KB, 下载次数: 4)
天可怜见,给点分啦、鲜花啦、掌声啦,能换点权、利的都行,请不吝赐之,多多益善。 |
|