File error: Data may have been lost.

  • Thread starter Thread starter Casper Hornstrup
  • Start date Start date
C

Casper Hornstrup

I use a template Excel document and ODBC to populate the document.

The connection string is:
Provider=MSDASQL;Driver={Microsoft Excel Driver (*.xls)};DBQ=" + Filename +
"; ReadOnly=False;FirstRowHasNames=1;MaxScanRows=8;

All expected rows are there, but when I open the file in Excel 2003. I get
two warnings:
"File error: Data may have been lost."

How can I remove or disable these warnings?

Casper Hornstrup
 
within the wb_open event, try to disable alerts using

for Off
application.displayalerts = false

for ON
application.displayalerts = true

Are you actually losing data?
 
I get the same result. Does this mean that the warnings are not generated by
the macro?
Actually it must be since the warnings are also displayed if I remove all
lines in the macro.
Is there anything else in Excel that can cause this? No data appear to be
lost.

Casper

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Call UpdateDatatypes
End Sub

Private Sub Workbook_Open()
Application.DisplayAlerts = False
Call UpdateDatatypes
End Sub

Private Sub UpdateDatatypes()
Dim myCell As Excel.Range
Dim myRng As Excel.Range
Dim wks As Excel.Worksheet

Application.ScreenUpdating = False

For Each wks In Me.Worksheets
Set myRng = wks.UsedRange.Cells

For Each myCell In myRng.Cells
If (Not Intersect(myCell, wks.Range("h:n")) Is Nothing) Then
myCell.Value = CStr(Replace(myCell.Value, ",", "."))
End If
If (Not Intersect(myCell, wks.Range("a:c")) Is Nothing) Then
myCell.NumberFormat = "@" 'Change to Text Format
myCell.Value = CStr("'" & CStr(myCell.Value)) 'Change to
Text Format
End If
Next
Next
End Sub
 
Hi Casper,

It will be greatly appreciated you tell me more information regarding this issue. Do you create the excel template in 2003? If possible, could you be so
kind to send these files to me? I will research this issue for you. My email address is: (e-mail address removed). (please remove "online" which is
used to avoid the spams)

Best regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks.
I've sent you the files.

Casper

Wei-Dong XU said:
Hi Casper,

It will be greatly appreciated you tell me more information regarding this
issue. Do you create the excel template in 2003? If possible, could you be
so
kind to send these files to me? I will research this issue for you. My
email address is: (e-mail address removed). (please remove "online" which
is
 
Hi Casper,

Based on my research, I'd suggest: please don't use macro in the Excel workbook.

If used, no matter we handle the Workbook_BeforeSave or Workbook_Open event, the error will be thrown.

If you create a new excel workbook and use no macro, your application will work very smoothly and the procuded workbook will reprot no error.

Please feel free to let me know if you have any further questions.

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Casper,

Currently we are working with product group on it. The problem is isolated
to Macros in excel file. The research may need some more time and we will
get back here with more information as soon as possible.

Thanks very much for your patience.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top