出现这种情况,一般有两种可能。1、从网上找的程序,没有把相应的过程或函数一起找来。
2、对子过程(或函数)的定义不一致。
例如:子过程test1做在某个工作表中,设定的是private属性。然后在模块中有一个全局程序test要调用其这个子过程,那么就会出现这种错误。更改方法:将这个子过程设置成全局的(public),并放在模块中,这样就可以解决了。
代码放在 ThisDocument中不会报错,代码放在模块中就会报错,因为Range需要限定
所有的Range前要加上ActiveDocument.
Sub Auto_Open()
ThisWorkbook.Application.Caption = APP_NAME_STR
CreateTableMenu
End Sub
Sub CreateTableMenu()
DeleteTableMenu
MenuBars(xlWorksheet).Menus.Add (MENU_REPORT_STR)
MenuBars(xlWorksheet).Menus(MENU_REPORT_STR).MenuItems.Add Caption:=MENU_REPORT_HISTDATA_SEARCH_STR, OnAction:="FormShow"
End Sub
Sub DeleteTableMenu()
On Error Resume Next
MenuBars(xlWorksheet).Menus(MENU_REPORT_STR).MenuItems(MENU_REPORT_HISTDATA_SEARCH_STR).Delete
On Error Resume Next
MenuBars(xlWorksheet).Menus(MENU_REPORT_STR).Delete
On Error Resume Next
End Sub
Sub FormShow()
UserForm2.Show
End Sub
Function ChangeDate(ByVal OldDate As String) As String
Dim DateLen, i As Long
Dim ss, EndDate As String
Dim mas As Integer
EndDate = ""
DateLen = Len(OldDate)
For i = 0 To DateLen - 1
ss = Mid$(OldDate, i + 1, 1)
mas = Asc(ss)
If mas <> 0 Then
EndDate = EndDate + ss
End If
Next i
ChangeDate = EndDate
End Function
Function GetVBString(ByVal OldStr As String) As String
Dim nLen, i As Long
Dim ss, strRet As String
Dim mas As Integer
Dim nSpacePos As Integer
nLen = Len(OldStr)
nSpacePos = nLen
For i = 0 To nLen - 1
ss = Mid$(OldStr, i + 1, 1)
mas = Asc(ss)
If mas = 0 Then
nSpacePos = i
Exit For
End If
Next i
GetVBString = Left(OldStr, nSpacePos)
End Function