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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you answer automaticly yes to save changes

Status
Not open for further replies.

Bvisual

Programmer
Jul 1, 2005
35
0
0
BE
the problem is i have a excel file i wont to edit and then save again to same path.

But then there comes the message in the line of:

Overwrite files ?

and you have to answer yes how do you make it so that it answers yes automaticly whitout showing the messagebox?


thx...
 
Could you post the code where you save the file?


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Code:
'SAVE DATA INTO existing EXEL FILE
        'Creating Excel application object
        Dim EXL As New Excel.Application
        'Checking if Excel object initiated succesfully or not
        If EXL Is Nothing Then
            MsgBox("Couldn't start Excel")
            Exit Function
        End If
        'Creating Excel Worksheet
        Dim WSheet As New Excel.Worksheet
        opening worksheet to excel workbooks
  
       
        WSheet = EXL.Workbooks.Open("source").Worksheets.Item(1)

        'Writing values in Work Sheet
        With WSheet

            .....................

        End With
        Try
            'Saving .xls file with Test.xls name 
            Dim File2 As System.IO.File
            Dim PATH2 As String = "source"

                       WSheet.SaveAs(PATH2)  [b]here is it that code has to be changed i think :)[/b]

        Catch
        End Try
        'setting up caption that "File Created"
        Me.Text = "File Created"
        'closing down workbook
        EXL.Workbooks.Close()

        EXL.Quit()

        While System.Runtime.InteropServices.Marshal.ReleaseComObject(EXL) <> 0
        End While

        EXL = Nothing
        GC.Collect()
        GC.WaitForPendingFinalizers()
 
What happens if you change the line

-> WSheet.SaveAs(PATH2)
to
WSheet.Save(PATH2)

If you start ecel, enter some data and then do a save as to save the file, then add more data and do a SAVE, you are NOT asked if you want to save. In other words, the file is simply over written. It MAY work the same wa in your code.

 
If i change it to save(path) it still asks me.

if i want to save the changed data.
 
After this:

Dim EXL As New Excel.Application
'Checking if Excel object initiated succesfully or not
If EXL Is Nothing Then
MsgBox("Couldn't start Excel")
Exit Function
End If

put this:

EXL.DisplayAlerts = False

and the popup will not appear.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 

i put in the command but now the messagebox will not appear but the data will not be saved after changing it


this is what i found that the dialog box is called maybe someone could do something with this?


EXL.FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogSaveAs)


thx for the help
 
With DisplayAlerts set to False, are you still using the SaveAs method? If so, try using the Save method.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
this is the code i am using i put the line in where you told me but the save and saveas command are not working
the code seems to open excel but doesnot do any changes to the file.

i think the messagebox has to be automaticly be answerd with yes without showing msgbox. but i dont now how to do this. All help is apprecheated
thx


Code:
'SAVE DATA INTO EXEL FILE
        'Creating Excel application object
        Dim EXL As New Excel.Application
        'Checking if Excel object initiated succesfully or not
        If EXL Is Nothing Then
            MsgBox("Couldn't start Excel")
            Exit Function
        End If

        EXL.DisplayAlerts = False   
        'Creating Excel Worksheet
        Dim WSheet As New Excel.Worksheet
        'Adding new worksheet to excel workbooks
        'WSheet = EXL.Workbooks.Add.Worksheets.Add ' CType(EXL.Workbooks.Add.Worksheets.Add, Excel.Worksheet)
        'WSheet = EXL.Workbooks.Open("D:\kassa\data.XLS")
        WSheet = EXL.Workbooks.Open("d:\kassa\data.XLS").Worksheets.Item(1)

        'Writing values in Work Sheet
        With WSheet

            'code for putting values in

        End With
        Try
            'Saving .xls file with data.xls name 
            Dim File2 As System.IO.File
            Dim PATH2 As String = "D:\kassa\data.XLS"

            If File2.Exists(PATH2) = True Then

                File2.Delete(PATH2)
            End If

            WSheet.SaveAs(PATH2) or wsheet.save(path2)

        Catch
        End Try

               'closing down workbook
        EXL.Workbooks.Close()

        EXL.Quit()

        While System.Runtime.InteropServices.Marshal.ReleaseComObject(EXL) <> 0
        End While

        EXL = Nothing
        GC.Collect()
        GC.WaitForPendingFinalizers()
 
i found this

EXL.AlertBeforeOverwriting = False


but it does not seem to do anything
but it seems to be to me the command i need to have or not ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top