astrogal
10-09-2001, 09:54 AM
I have a tool that opens an Excel template, reads data from a text file and places the parsed data into pertinent cells in the spreadsheet. The spreadsheet template has formulas which uses the data that is input. I then save the spreadsheet and reopen to ensure the formulas are calulated from the new data. The data in the cells that have the formulas however do not seemed to be refreshed on the save when an instance of Excel is not already open. If an instance of Excel is already open the tool works fine. The tool does however have code to open Excel so I would think it should work. Here's part of it. Help would really be appreciated!
Set xlApp = New Excel.Application 'open Excel
xlApp.Visible = True
Set xlBook1 = GetObject(ttq_template$) 'open the appropriate workbook where ttq_template$ is the path string
xlBook1.Parent.Windows(xlBook1.Name).Visible = True
Set xlSheet1 = xlBook1.Worksheets(1) 'open first sheet of workbook
Code does some stuff, like parsing data file and placing in certain spreadsheet cells....
'The save part...
xlSheet1.SaveAs "apppathonmysystem\" + cmdout_ttq$ 'saving the spreadsheet as the outputname
'The Close part...
'Closing book to refresh data
If xlBook1.Name <> "" Then
xlBook1.Close
End If
Set xlBook1 = Nothing
Set xlSheet1 = Nothing
If xlApp Is Excel.Application Then
xlApp.Quit
End If
Set xlApp = Nothing
'The reopen part...
Set xlApp = New Excel.Application 'open Excel
xlApp.Visible = True
Set xlBook1 = GetObject("apppathonmysystem\" + cmdout_ttq$ + ".xls") 'open the appropriate workbook
xlBook1.Parent.Windows(xlBook1.Name).Visible = True
Set xlSheet1 = xlBook1.Worksheets(1) 'open first sheet of workbook
When I step through and Excel is open on my system (could be just application, no workbook Or w/blank workbook Or existing non-related workbook, it doesn't matter) this works fine. If there isn't an instance those cells have #Value as if the cells with the formulas weren't refreshed.
Thanks!
Set xlApp = New Excel.Application 'open Excel
xlApp.Visible = True
Set xlBook1 = GetObject(ttq_template$) 'open the appropriate workbook where ttq_template$ is the path string
xlBook1.Parent.Windows(xlBook1.Name).Visible = True
Set xlSheet1 = xlBook1.Worksheets(1) 'open first sheet of workbook
Code does some stuff, like parsing data file and placing in certain spreadsheet cells....
'The save part...
xlSheet1.SaveAs "apppathonmysystem\" + cmdout_ttq$ 'saving the spreadsheet as the outputname
'The Close part...
'Closing book to refresh data
If xlBook1.Name <> "" Then
xlBook1.Close
End If
Set xlBook1 = Nothing
Set xlSheet1 = Nothing
If xlApp Is Excel.Application Then
xlApp.Quit
End If
Set xlApp = Nothing
'The reopen part...
Set xlApp = New Excel.Application 'open Excel
xlApp.Visible = True
Set xlBook1 = GetObject("apppathonmysystem\" + cmdout_ttq$ + ".xls") 'open the appropriate workbook
xlBook1.Parent.Windows(xlBook1.Name).Visible = True
Set xlSheet1 = xlBook1.Worksheets(1) 'open first sheet of workbook
When I step through and Excel is open on my system (could be just application, no workbook Or w/blank workbook Or existing non-related workbook, it doesn't matter) this works fine. If there isn't an instance those cells have #Value as if the cells with the formulas weren't refreshed.
Thanks!