We help IT Professionals succeed at work.
Get Started

VBS script - Need to change location of output file

mkraemer11 asked
Last Modified: 2012-05-09
The following script places the outputfile on the desktop.  I need it  to be placed in "C:\FaxConfirmation".  Can anyone tell me what I need to add in the coding and where?

' Specify the template xls file that you wish to update here
strTemplateFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "FaxConfirmation.xls"

Set objExcel = CreateObject("Excel.Application")
Const xlUp = -4162
Const xlDown = -4121
Const xlAnd = 1
objExcel.Visible = True

'First open the template workbook
objExcel.Workbooks.Open strTemplateFile
Set objTemplateWB = objExcel.ActiveWorkbook
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "CSV Files (*.csv)|*.csv;All Files (*.*)|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = "."
intResult = objDialog.ShowOpen

If intResult = 0 Then
      MsgBox "No file was selected."
      objExcel.Workbooks.Open objDialog.FileName
      Set objCSVWB = objExcel.ActiveWorkbook
      objCSVWB.Sheets(1).UsedRange.Copy objTemplateWB.Sheets(1).Cells(65536, "A").End(xlUp).Offset(1, 0)
      objExcel.ActiveWorkbook.Close False
      objExcel.ActiveWorkbook.SaveAs objExcel.ActiveWorkbook.Path & "\" & Replace(objExcel.ActiveWorkbook.Name, ".xls", "") & "_" & FormatDateToString(Now) & ".xls"
      objExcel.ActiveWorkbook.Close False
End If

Function FormatDateToString(dDateTime)
      FormatDateToString =      Year(dDateTime) & "-" &_
                        Right("00" & Month(dDateTime), 2) & "-" &_
                        Right("00" & Day(dDateTime), 2) & "-" &_
                        Right("00" & Hour(dDateTime), 2) & "-" &_
                        Right("00" & Minute(dDateTime), 2) & "-" &_
                        Right("00" & Second(dDateTime), 2)
End Function
Watch Question
IT Manager
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE