2017-09-15 84 views
-3

我正在工資的Excel文件。我想在重命名後自動刪除這個Excel文件。我的意思是如果任何人在重命名後打開它,它將被自動刪除。我的代碼正在工作,但它也將其刪除而不重命名該文件。自動刪除excel文件,如果它改名

Private Sub workbook_open() 
    Dim xFileName As String 
    xFileName = "Salary.xlsm" 
    If xFileName <> "True" Then 
     Dim ws As Worksheet 
     For Each ws In ThisWorkbook.Worksheets 
      ws.Visible = xlSheetVisible 
     Next ws 
     Sheets("User").Visible = xlVeryHidden 
     Sheets("Pass").Visible = xlVeryHidden 
    End If 

    If xFileName <> "False" Then 
     Me.ChangeFileAccess xlReadOnly 
     MsgBox "File Name Changed- iTach" 
     Kill Me.FullName 
     Application.Quit 
    End If 
End Sub 
+0

@iTech這不是一個VBScript – GTAVLover

+0

ØYaaaa。對不起。現在發佈更新。我只有上面的代碼。如果您瞭解這一點,請提供我的解決方案。 – iTech

回答

0

請嘗試下面的代碼..

 Private Sub workbook_open() 
     Dim xFileName As String 
     xFileName = "salary.xlsm" 
     If xFileName = ThisWorkbook.Name Then 
      Dim ws As Worksheet 
      For Each ws In ThisWorkbook.Worksheets 
      ws.Visible = xlSheetVisible 
      Next ws 
      Sheets("User").Visible = xlVeryHidden 
      Sheets("Pass").Visible = xlVeryHidden 
     Else 
      Me.ChangeFileAccess xlReadOnly 
      MsgBox "File Name Changed- iTach" 
      Kill Me.FullName 
      Application.Quit 
     End If 
     End Sub 
+0

工作很好.....謝謝。 – iTech