Forum Discussion

mfoster711's avatar
mfoster711
Regular Contributor
12 years ago

Excel Workbook SaveAs FileFormat


TemplateFile = "\\server\TemplateName.xls"

Set objExcel = Sys.OleObject("Excel.Application")


Set objWorkBook = objExcel.Workbooks.Add(TemplateFile)

FileFormat = -4143




objWorkBook.SaveAs(LogFileName, FileFormat)


 


TestComplete is showing this as a Snytax error on the SaveAs line.  Why? If I remove the second parameter it works but I need to specifiy fileformat.

6 Replies

  • VLapidus's avatar
    VLapidus
    Frequent Contributor
    You forgot to use Call:



    Call objWorkBook.SaveAs(LogFileName, FileFormat)
  • sastowe's avatar
    sastowe
    Super Contributor
    Or you don't need call if you leave off the parenthesis



    objWorkbook.SaveAs LogFileName, FileFormat



    for a sub routine.
  • mfoster711's avatar
    mfoster711
    Regular Contributor
    I am having the same issue with the following Close statement:



    objWorkBook.Close(True, "c:\MyTestFile.xlsx")



    TestComplete is marking this line as  a syntax error. 





  • mfoster711's avatar
    mfoster711
    Regular Contributor
    Both of those replies worked. I am still adjusting to vbscript and that was a rookie mistake.
  • sastowe's avatar
    sastowe
    Super Contributor
    We've all make them. I am no rookie, and I still make them. I pulled an embarassing dumb bunny earlier this week. We all had a fun laugh at my mistake. I turn a very interesting shade of red when it happens. :)