The following method allows you to save a Microsoft Excel file to a users hard disc.

Source Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
' @Author - Alexander Bolte
' @ChangeDate - 2015-01-05
' @Description - Saves provided excel file under given file path.
' Overwrites any existing file in same directory with same name.
' @Param xlFile - An object of type Excel.Workbook.
' @Param trgPath - A String holding a path to save a provided file to.
' @Returns true, if a provided excel file has been saved successfully
' else false.
Function saveXlFile(xlFile, trgPath) ' As Boolean
  Dim ret ' As Boolean
  Dim fso ' As Scripting.FileSystemObject
 
  On Error Resume Next
 
  ' Delete file if it already exists.
  deleteFileOnHD trgPath
  ' Save provided file under given file path.
  xlFile.SaveAs trgPath
  ret = True
 
  If Err.Number <> 0 Then
    Err.Clear
  End If
 
  saveXlFile = ret
End Function

 

Referenced Methods

Below list shows references to other methods.

VBScript to delete file