Click to See Complete Forum and Search --> : Sockets and Excel automation


al_paso
May 24th, 2001, 05:52 PM
I am trying to do some stuff with excel automation.
What I have to do is Saveas an excel file in a CSV format and pass the data line by line via socket connection to a client.
My problem is when I SaveAs an excel file into a csv file and try to close excel and Quit it always asks me to save the file. I do not want this prompt as I will be running this from a DLL and this could hang the DLL. the reason why this happens is sine I am saving the file in a different format.
Is there a way to overide or forcefullt save the file. I have tried calling Save immediately after but the message box still comes up.
Any help on this would be appreciated.

Thanks in advance

Cimperiali
May 25th, 2001, 05:28 AM
Title of your question is a little bit confusing: "How to save Excel from Vb without be Prompted" would have lead to quicker answers...
msdn example:

Not to be prompted:
discarding changes:
Workbooks("BOOK1.XLS").Close SaveChanges:=False
saving changes:
Workbooks("BOOK1.XLS").Close SaveChanges:=True, Filename:="PathAndyourfilename"

from msdn:

Close Method Example

This example closes all open workbooks. If there are changes in any open workbook, Microsoft Excel displays the appropriate prompts and dialog boxes for saving changes.

Workbooks.Close


This example closes Book1.xls and discards any changes that have been made to it.
Workbooks("BOOK1.XLS").Close SaveChanges:=False


for more info:

Close Method
Closes the object. The Workbooks collection uses Syntax 1. Window and Workbook objects use Syntax 2.

Syntax 1

expression.Close

Syntax 2

expression.Close(SaveChanges, FileName, RouteWorkbook)

expression Required. An expression that returns an object in the Applies To list.

SaveChanges Optional Variant. If there are no changes to the workbook, this argument is ignored. If there are changes to the workbook and the workbook appears in other open windows, this argument is ignored. If there are changes to the workbook but the workbook doesn't appear in any other open windows, this argument specifies whether changes should be saved, as shown in the following table.

Value Action
True Saves the changes to the workbook. If there is not yet a file name associated with the workbook, then FileName is used. If FileName is omitted, the user is asked to supply a file name.
False Does not save the changes to this file.
Omitted Displays a dialog box asking the user whether or not to save changes.


FileName Optional Variant. Save changes under this file name.

RouteWorkbook Optional Variant. If the workbook doesn't need to be routed to the next recipient (if it has no routing slip or has already been routed), this argument is ignored. Otherwise, Microsoft Excel routes the workbook as shown in the following table.

Value Meaning
True Sends the workbook to the next recipient.
False Doesn't send the workbook.
Omitted Displays a dialog box asking the user whether the workbook should be sent.



Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.

nederlof
May 25th, 2001, 01:53 PM
Hi,

I can propose two options:
1. set Application.DisplayAlerts=False before you close the workbook (and back to True right after that, just in case...)
2. set the workbook's "Saved" property to True before you close it: Workbooks("Book1.xls").Saved=True

I think these both should work.

Leo

al_paso
May 26th, 2001, 08:29 PM
Thanks ...that worked!!