'開啟EXCEL文件 '*************************************************************************************************** '別忘記新增 參考 EXCEL 11
Dim objExcel As Object = CreateObject("Excel.Application") '使用完後 就釋放資源 故使用Using Dim objBook As Object
objBook = objExcel.Workbooks.Open(My.Application.Info.DirectoryPath & "\output.xlt")
With objExcel
'.Visible = True
'.DisplayAlerts = False
'MsgBox(My.Application.Info.DirectoryPath)
End With
With objExcel.sheets("sheet1")
.Range("A1").offset(n, 0).Value =N
End With
Dim Ts As String = DateAndTime.Now.ToString()
Ts = Replace(Ts, "/", "-")
Ts = Replace(Ts, ":", "-")
Dim FN As String = "基本資料_" & Ts & ".xls" '建議電話只取前30個字以避免錯誤!
'Save the Workbook and quit Excel.
'objBook.SaveAs(My.Application.Info.DirectoryPath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & ".xls")
objBook.SaveAs(My.Application.Info.DirectoryPath & "\" & FN)
objBook = Nothing
objExcel.Quit()
objExcel = Nothing
GC.Collect()
沒有留言:
張貼留言