您的位置:首页 > 其它

第22章 应用程序部署策略

2010-01-21 13:16 197 查看
22.1 选择方式

22.1.1 我喜欢原型程序

22.1.2 使用模板重复成功操作

代码清单22.1: 实现伪模板功能

代码

'代码清单22.4: 修复工作薄的简单程序
Sub FixWorkbook(wb As Workbook)
Dim ws As Worksheet

Set ws = wb.Worksheets("Sheet1")

ws.Range("A1").Formula = "=b1+c1"
ws.Range("A2").Formula = "=b2+c2"
ws.Range("A3").Formula = "=b3+c3"

Set ws = Nothing
End Sub

Sub ProcessFileBatch()
Dim nIndex As Integer
Dim vFiles As Variant
Dim wb As Workbook
Dim bAlreadyOpen As Boolean
Dim sFile As String

On Error GoTo ErrHandler

vFiles = GetExcelFiles("")

If Not IsArray(vFiles) Then
Debug.Print ""
Exit Sub
End If

Application.ScreenUpdating = False

For nIndex = 1 To UBound(vFiles)
If IsWorkbookOpen(CStr(vFiles(nIndex))) Then
Set wb = Workbooks(GetShortName(CStr(vFiles(nIndex))))
Debug.Print "" & wb.Name
bAlreadyOpen = True
Else
Set wb = Workbooks.Open(CStr(vFiles(nIndex)), False)
Debug.Print "" & wb.Name
bAlreadyOpen = False
End If

Application.StatusBar = "" & wb.Name

FixWorkbook wb

If Not bAlreadyOpen Then
Debug.Print "" & wb.Name
wb.Close True
End If

Next

ErrHandler:
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub

'代码清单6.2
Function IsWorkbookOpen(sWorkbook As String) As Boolean
End Function

'代码清单5.6
Function GetExcelFiles(sTitle As String) As Variant
End Function

'代码清单5.8
Function GetShortName(sLongName As String) As Variant
End Function

'代码清单5.8
Function BreakdownName(sFullName As String, byref sname As String, byref sPath As String) As Variant
End Function

'代码清单5.8
Function FileNamePosition(sFullName As String) As Integer
End Function
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: