vba之小功能記錄--資料另存

13920081667發表於2014-10-28
編碼環境: office2010
背景環境:合同控制部實現簡單的資料複製。
程式程式碼:
Private Sub 另存為_Click()
Application.DisplayAlerts = False
Dim wb As Workbook
Dim idate As String
''''''''''''獲取系統時間''''''''''''
idate = Date
''''''''''''彈出輸入框''''''''''''
sr = Application.InputBox("請輸入要儲存的檔名", "輸入提示")
''''''''''''新增新的excel檔案''''''''''''
Set wb = Workbooks.Add
''''''''''''檔案儲存在當前目錄下,以輸入的文字命名''''''''''''
wb.SaveAs ThisWorkbook.Path & "/" & sr & ".xls"
ThisWorkbook.Sheets("表1").Range("a:t").copy wb.Sheets("sheet1").Range("a:t")
ActiveSheet.Name = "表1"
wb.Sheets("表1").Range("P2").Value = idate
Columns("P:P").ColumnWidth = 15.25
ActiveWindow.Zoom = 80
wb.Save
i = 0
Do
    i = i + 1
    If Range("a" & i) = "合計" Then
    num = i - 1
    Exit Do
    End If
Loop
ThisWorkbook.Worksheets("表1").Range("a4:p" & num).ClearContents
ThisWorkbook.Save
wb.Save
Application.DisplayAlerts = True
End Sub

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29987527/viewspace-1311757/,如需轉載,請註明出處,否則將追究法律責任。

相關文章