|
本帖最后由 liucqa 于 2015-7-12 22:04 编辑
代码还是能dump出来的
Module: ----------------------------------- mdlVBA -----------------------------------
Attribute VB_Name = "mdlVBA"
Option Explicit ''''显式变量声明
Option Private Module ''''外部工程禁用
Public Const gstrUSER_MSG_TITLE As String = "ExcelHome.Net"
Private Function FieldsExists(intWsIndex As Integer, Optional blnDisplayAlerts As Boolean = True) As Boolean
''''功能:检查指定工作表的字段名称与内置字段名称是否匹配
''''参数:intWsIndex:=工作表索引;blnDisplayAlerts:=不匹配时是否弹出警告对话框
Dim Ws As Excel.Worksheet
Dim astrFieldNames() As String
Dim vntHeader As Variant
Dim I As Integer
Dim intColumnSize As Integer
On Error GoTo ErrorHandler
Select Case intWsIndex
Case 1
Set Ws = Sheet1
intColumnSize = 10 ''''字段数量
ReDim astrFieldNames(1 To intColumnSize)
astrFieldNames(1) = "OfficeID"
astrFieldNames(2) = "OfficeName"
astrFieldNames(3) = "Region"
astrFieldNames(4) = "Province"
astrFieldNames(5) = "City"
astrFieldNames(6) = "Address"
astrFieldNames(7) = "StartData"
astrFieldNames(8) = "ExpiryData"
astrFieldNames(9) = "OfficeArea"
astrFieldNames(10) = "Reviser"
End Select
vntHeader = Ws.Cells(1, 1).Resize(1, intColumnSize).Value ''''标题行
For I = 1 To intColumnSize
If Not StrComp(vntHeader(1, I), astrFieldNames(I), vbTextCompare) = 0 Then Exit For
Next
If I > intColumnSize Then
FieldsExists = True
Else
If blnDisplayAlerts = True Then
MsgBox Ws.Name & Chr$(34) & vntHeader(1, I) & Chr$(34) & "与标准字段名" & Chr$(34) & astrFieldNames(I) & Chr$(34) & "不匹配。", vbExclamation, gstrUSER_MSG_TITLE
End If
End If
On Error GoTo 0
Exit Function
ErrorHandler:
If ExcelHomeErrorHandler("Private Function FieldsExists") = True Then Resume Next
End Function
Public Function FileExists(strFileName As String) As Boolean
''''功能:判断文件或者文件夹是否存在
''''参数:strFileName:=待考查的文件或者文件夹的完整路径
FileExists = (Len(Dir(strFileName, vbDirectory)) > 0)
End Function
Public Function ExcelHomeErrorHandler(strProcName As String) As Boolean
''''功能:错误处理程序
''''参数:strProcName:=出错的过程名称
Dim strErrMessage As String
strErrMessage = "程序运行在" & Chr$(34) & strProcName & Chr$(34) & "过程时发生错误。" & vbCrLf & _
"错误时间:" & Now & vbCrLf & _
"错误代号:" & Err.Number & vbCrLf & _
"错误原因:" & Err.Description
Err.Clear ''''清除错误
If MsgBox(strErrMessage & vbCrLf & "是否继续?", vbExclamation + vbYesNo, gstrUSER_MSG_TITLE) = vbYes Then
ExcelHomeErrorHandler = True
Else
With Application
.StatusBar = False ''''清空状态栏
.DisplayAlerts = True ''''恢复警告对话框
.EnableEvents = True ''''恢复事件
.ScreenUpdating = True ''''恢复屏幕更新
End With
ExcelHomeErrorHandler = False
End If
End Function
|
|