Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing data to Excel, igonre save

Status
Not open for further replies.

elibb

Programmer
Oct 22, 2001
335
MX
hi, i have a vb6.0 application, and im writing some data from it to an excel template, everything works fine, but i print the page and then i want to close excel without promting if i want to save my work.
i tried to save as the file, to a predermitaed file i set, but then the scond time i get a message if i want to overwrite the file that already exists.
im sure there is a way to avoid this, but i cannt find it, any ideas??

my code looks more or less like this:

Code:
Dim oExcelApp   As Excel.Application
Dim oWs         As Excel.Worksheet
Dim oWb         As Excel.Workbook
Dim Path As String


Set oExcelApp = CreateObject("EXCEL.APPLICATION")
oExcelApp.Visible = True
oExcelApp.Workbooks.Open FileName:=App.Path & "\Fac2.xls", ReadOnly:=True, ignoreReadOnlyRecommended:=True
Set oWs = oExcelApp.ActiveSheet
Set oWb = oExcelApp.ActiveWorkbook

With oWs

.... i write all my data to the object here

Code:
.PrintOut

End With
oWs.SaveAs App.Path & "/tmp.xls"

oExcelApp.Application.Quit

Set oExcelApp = Nothing
Set oWs = Nothing
Set oWb = Nothing

thank You very much!!
Eli
 
With:
[tt]oExcelApp.DisplayAlerts=False[/tt]
excel executes the default answer without prompting. In that case "no overwrite" is the default, so rather you have to delete file if exists, and next do SaveAs.

combo
 
You need to get rid of the old file first with

If Dir(App.Path & &quot;/tmp.xls&quot;) <> &quot;&quot; Then Kill App.Path & &quot;/tmp.xls&quot;

Then you need to save the workbook with

oWb.SaveAs App.Path & &quot;/tmp.xls&quot;

and then tell Excel it was saved with

oWb.Saved = True

 
i dont want to save the file, i was doing it because excel asked me if i wanted to save it when i quited the application,but with the

Code:
oExcelApp.DisplayAlerts=False

works exactly the way i want..

thank You!!!

Eli
 
I suggest you should have closed the workbook first, then quit the application.

ActiveWorkbook.Close false 'the false is for the SaveChanges parameter
oExcelApp.quit 'and there aren't any books to pop up a dialog about.

just my $0.02
 
set the workbook property &quot;saved&quot; to TRUE.
You can set this property to True if you want to close a modified workbook without either saving it or being prompted to save it.


Attitude is Everything
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top