上週末,XX給我抱怨:由於計算績效獎金,把2我的的工資發錯了,還被扣了500元。問的原因得知,她每月要處理十來個excel表格,每次都要手動修改裏面的值,若是修改了一處,其餘地方也要修改,而後還要多處地方覈對。致使光這件事情就要消耗三四天,傷神費力。git
我就問她,整個是否是都是機械性重複的工做,若是是的話,徹底能夠用電腦來代替。而後我就幫她找工具來優化她的工做,減小出錯機會。github
總結:如今目前找到的都是web版的系統,都須要在線部署。沒有找到桌面版本,能夠當即使用的那種。都不太適合目前的狀況。web
實現功能(下載demo):數據庫
1 Sub ChangeFileFormat(xltxFolder, xlsxFolder) 2 3 Dim strCurrentFileExt As String 4 Dim strNewFileExt As String 5 Dim objFSO As Object 6 Dim objFolder As Object 7 Dim objFile As Object 8 Dim xlFile As Workbook 9 Dim strNewName As String 10 Dim strXltxFolderPath As String 11 Dim strXlsxFolderPath As String 12 13 Set objFSO = CreateObject("Scripting.FileSystemObject") 14 15 strCurrentFileExt = ".xltx" 16 strNewFileExt = ".xlsx" 17 18 strXltxFolderPath = ThisWorkbook.Path & "\" & xltxFolder & "\" 19 strXlsxFolderPath = ThisWorkbook.Path & "\" & xlsxFolder & "\" 20 21 If Not objFSO.FolderExists(strXltxFolderPath) Then '判斷指定文件夾是否存在 22 MsgBox "【模板文件】文件夾不存在" 23 Exit Sub 24 End If 25 26 If Not objFSO.FolderExists(strXlsxFolderPath) Then '判斷指定文件夾是否存在 27 fs.CreateFolder strXlsxFolderPath 28 End If 29 30 Set objFolder = objFSO.getfolder(strXltxFolderPath) 31 For Each objFile In objFolder.Files '循環全部的模板文件 32 strNewName = objFile.Name 33 If Right(strNewName, Len(strCurrentFileExt)) = strCurrentFileExt Then 34 Application.AskToUpdateLinks = False '關閉程序詢問更新連接提示 35 Application.DisplayAlerts = False 36 ThisWorkbook.UpdateLinks = xlUpdateLinksAlways '更新連接 37 38 Set xlFile = Workbooks.Open(objFile.Path, , True) '讀取模板文件 39 For Each sh In xlFile.Sheets '替換文件中的公式 40 sh.UsedRange.Value = sh.UsedRange.Value 41 Next 42 43 strNewName = Replace(strNewName, strCurrentFileExt, strNewFileExt) '替換文件名爲新的文件名 44 Select Case strNewFileExt 45 Case ".xlsx" 46 xlFile.SaveAs strXlsxFolderPath & strNewName, XlFileFormat.xlOpenXMLWorkbook '保存爲不帶宏的excel 47 Case ".xlsm" 48 xlFile.SaveAs strXlsxFolderPath & strNewName, XlFileFormat.xlOpenXMLWorkbookMacroEnabled '保存爲帶宏的excel 49 End Select 50 xlFile.Close 51 Application.AskToUpdateLinks = True 52 Application.DisplayAlerts = True 53 End If 54 Next objFile 55 56 ClearMemory: 57 strCurrentFileExt = vbNullString 58 strNewFileExt = vbNullString 59 Set objFSO = Nothing 60 Set objFolder = Nothing 61 Set objFile = Nothing 62 Set xlFile = Nothing 63 strNewName = vbNullString 64 strFolderPath = vbNullString 65 End Sub
在這個過程當中,考慮的時候,使用到了:模塊,數據惟一性,避免交叉引用,這些開發中的經驗。服務器
其實我以爲,整個過程當中,VBA的編寫佔據了我最多的時間。查資料,找文檔。(百度就是個大坑!!!)函數
不熟悉Excel函數致使,當我寫完一個宏的時候,發現VLOOKUP已經早就實現這個功能了。工具