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

Auto Replace for the Excel Save using VB 1

Status
Not open for further replies.

basicyen

IS-IT--Management
Oct 4, 2002
15
US
All experts out there...help me please

I am writting a simple application using Vb6.0 to
access the Excel file, make modification and save with
the same file name. And I keep getting a prompt message
as follow:
The file 'H:\work\ExcelFile.xls' already exist.
Do you want to replace the existing file? Yes or No button

How do I auto replace the save, so that I don't have to get
this message again.

The following is the syntax I used in my program
Dim objectExcel as object
.
.
.
objectExcel.Application.ActiveWorkbook.SaveAs
FileName:="C:\work\ExcelFile.xls"


Help please

Thanks

 
why not use the .Save Method instead?

Save Method

Saves changes to the specified workbook.

Syntax

expression.Save

expression Required. An expression that returns a Workbook object.

Remarks

To open a workbook file, use the Open method.

To mark a workbook as saved without writing it to a disk, set its Saved property to True.

The first time you save a workbook, use the SaveAs method to specify a name for the file.
 
I did you the save method as follow and still prompt me with the message that the file already exist. It does not do the auto replace save.

Dim objectExcel as Object
.
.
If objectExcel.FileExists
("C:\work\ExcelFile.xls") Then
objectExcel.Workbooks.Open "C:\Work\ExcelFile.xls"
SheetName = objectExcel.Activeworkbooks.sheets(1).Name
Set obWorkSheet = objectExcel.Activeworkbooks.sheets(SheetName)
End If

obExcelApp.Visible = False

With obExcelApp.Application
.Range("A1:E1").Select
.Selection.Font.Bold = True
.Cells.Select
.Selection.Columns.AutoFit
.Range("A10").Select
fIELD1 = .Range("A10").Value
.Cells(1, 1).Value = "Store4"
End With

objectExcel.Save

Help please
 
objectExcel.Application.ActiveWorkbook.Save

or

Dim objectExcel as Object
Dim objWorkBook As Object
.
.
.
If objectExcel.FileExists ("C:\work\ExcelFile.xls") Then
set objWorkBook = objectExcel.Workbooks.Open ("C:\Work\ExcelFile.xls")
.
.
.
objWorkBook.Save
.
.
.
 
Folks... I believe I found the answer and I test and It works just great. I am open for any further advice, the more is the better

Here the syntax in lieu of "objectExcel.Save or ObjectExcel.SaveAs..."

The alternate save the excel file to the existing file:
"objectExcel.ActiveWorkbook.Close SaveChanges:=True"


By the way... I am at Los Angeles County...I am looking for any good VB group Club. Any advice????

Thanks again

 
JustinEzequiel.... your answer and example are well documented and perfect. I trully appreciate your kind and quick response. By the way ... any good books that you know as a reference for "VB programming with Excel file" and "VB programming with MicrosotWord - mail merge, template..etc"

Thanks
 
Always glad to be of help LOL
We only have Microsoft Office 97 Visual Basic Programmer's Guide (Microsoft Press).
Haven't used it much except for looking up things so I cannot comment on whether it is good or not.
I know the others in this forum can give you more info on books and such.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top