I have the following code that creates an Excel file, puts data into the cells but now I need to save the file. I cannot get the syntax correct for the .......SaveAs FileName:= "xxxxxxx"
Set obj = CreateObject("Excel.Application")
Set oApp = obj.Application
Set oWb = oApp.Workbooks.Add
Set oWb = oApp.Workbooks(1)
Set oWs1 = oWb.Worksheets("sheet1")
oWs1.Cells(1, 1).Value = "column1"
oWs1.Cells(1, 2).Value = "column2"
oWs1.Cells(1, 3).Value = "column3"
...
...
Then:
f1 = "mydata1"
f2 = "mydata2"
f3 = "mydata3"
...
...
This all works OK, but now I need to save the newly created file, so:
obj.ActiveWorkbook.SaveAs FileName:="C:\MyPath_filename.xlsx", FileFormat:=xlsx
But I keep getting the "Object doesn't support this property or method" Run-time error at the 'SaveAs' code line.
Any assistance in getting the correct Dim, set and SaveAs syntax would be appreciated.
Set obj = CreateObject("Excel.Application")
Set oApp = obj.Application
Set oWb = oApp.Workbooks.Add
Set oWb = oApp.Workbooks(1)
Set oWs1 = oWb.Worksheets("sheet1")
oWs1.Cells(1, 1).Value = "column1"
oWs1.Cells(1, 2).Value = "column2"
oWs1.Cells(1, 3).Value = "column3"
...
...
Then:
f1 = "mydata1"
f2 = "mydata2"
f3 = "mydata3"
...
...
This all works OK, but now I need to save the newly created file, so:
obj.ActiveWorkbook.SaveAs FileName:="C:\MyPath_filename.xlsx", FileFormat:=xlsx
But I keep getting the "Object doesn't support this property or method" Run-time error at the 'SaveAs' code line.
Any assistance in getting the correct Dim, set and SaveAs syntax would be appreciated.