Sub 保存文件() Dim SaveFile Dim PersonnelName, PersonnelIdCard As String Application.ScreenUpdating = False Application.DisplayAlerts = False PersonnelName = Replace(ActiveSheet.Cells(11, 3), Chr(32), "") PersonnelIdCard = Replace(ActiveSheet.Cells(11, 8), Chr(32), "") If Len(PersonnelName) > 0 And Len(PersonnelIdCard) > 0 Then SaveFile = Application.GetSaveAsFilename(InitialFileName:=PersonnelName & "(" & PersonnelIdCard & ")", _ fileFilter:="MicroSoft Office Excel 工作薄 (*.xls), *.xls", Title:="以本人姓名和身份證號另存文件") If SaveFile <> False Then If Replace(SaveFile, (Left(SaveFile, InStrRev(SaveFile, "\"))), "") = PersonnelName & "(" & PersonnelIdCard & ").xls" Then ActiveWorkbook.SaveAs Filename:=SaveFile Else MsgBox "請使用指定文件名保存!" End If End If Else ActiveWorkbook.Save End If Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub |
|