Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default System.AccessViolationException on VS2005 and Microsoft.Office.Int

Hi, I've a Problem when i try to save an Excel Woorkbook From VB2005, the
program crash and send me the next error message
"System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt."

please Help me.

the PC where the program was write, has Windows XP SP2 and Office 2003, and
the PC with the problem has Windows 2000 SP4 and Office XP Professional.

this is the code:


Private Sub Guardar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Guardar.Click
Dim Fecha As Date = Fecha_Asignacion.Value

SaveFileDialog1.InitialDirectory = "mydocuments"
SaveFileDialog1.Filter = "Archivo de Microsoft Excel (*.xls)|*.xls"
SaveFileDialog1.FileName = "Asignaciones " & Format(Fecha, "yyMMdd")
& ".xls"

SaveFileDialog1.FilterIndex = 1
SaveFileDialog1.RestoreDirectory = True

If SaveFileDialog1.ShowDialog() =
System.Windows.Forms.DialogResult.OK Then
Dim Nombre_Archivo As String = SaveFileDialog1.FileName
Dim oExcel As New Microsoft.Office.Interop.Excel.Application()
Dim oBook As Microsoft.Office.Interop.Excel.Workbook
Dim oWorksheet As Microsoft.Office.Interop.Excel.Worksheet
oExcel.DisplayAlerts = False

' Creamos un nuevo libro de trabajo de Excel.
oBook = oExcel.Workbooks.Add

'aƱadimos una hoja de excel que es donde vamos a trabajar
oWorksheet = oBook.Worksheets.Add
oWorksheet.Name = "Asignaciones_" & Format(Fecha, "ddMMyyyy")
oWorksheet.Activate()
oWorksheet = oBook.Worksheets.Item("hoja1")
oWorksheet.Delete()
oWorksheet = oBook.Worksheets.Item("hoja2")
oWorksheet.Delete()
oWorksheet = oBook.Worksheets.Item("hoja3")
oWorksheet.Delete()

oWorksheet = oBook.Worksheets.Item("Asignaciones_" &
Format(Fecha, "ddMMyyyy"))
oWorksheet.Activate()

oWorksheet.Range("A1").Select()
Me.DataGridView1.ClipboardCopyMode =
DataGridViewClipboardCopyMode.EnableAlwaysIncludeH eaderText
Me.DataGridView1.SelectAll()
Clipboard.SetDataObject(Me.DataGridView1.GetClipbo ardContent())
oWorksheet.Paste()
oWorksheet.SaveAs(Nombre_Archivo)

oWorksheet = Nothing
oBook.Save()
Do While Not oBook.Saved
System.Windows.Forms.Application.DoEvents()
Loop
oBook.Saved = True
oBook.Close(False)

oExcel.Workbooks.Close()
oExcel.Quit()


oBook = Nothing
oExcel = Nothing

System.GC.Collect()
GC.WaitForPendingFinalizers()

Try
System.GC.Collect()
Catch N As Exception
Debug.Print(N.Message)
End Try
MsgBox("El Archivo se ha generado con exito",
MsgBoxStyle.Information)
Me.DataGridView1.DataSource = Nothing

End If
end sub


and this is error Code:

************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt.
at Microsoft.Office.Interop.Excel._Worksheet.SaveAs(S tring Filename,
Object FileFormat, Object Password, Object WriteResPassword, Object
ReadOnlyRecommended, Object CreateBackup, Object AddToMru, Object
TextCodepage, Object TextVisualLayout, Object Local)
at WindowsApplication1.Reporte1.Guardar_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&
m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies ************** mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
GestionCPP
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase:
file:///C:/Documents%20and%20Settings/D800782/Configuraci%F3n%20local/Apps/2.0/Q6E8CYWV.W6V/E9XRW8V8.H5R/gest..tion_fc8add938e35284e_0000.0001_a2d7162722ad b1a3/GestionCPP.exe

----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll

----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll

----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll

----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll

----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll

----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll

----------------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll

----------------------------------------
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll

----------------------------------------
System.Deployment
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase:
file:///C:/WINNT/assembly/GAC_MSIL/System.Deployment/2.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll

----------------------------------------
Microsoft.Office.Interop.Excel
Assembly Version: 11.0.0.0
Win32 Version: 11.0.5530
CodeBase:
file:///C:/Documents%20and%20Settings/D800782/Configuraci%F3n%20local/Apps/2.0/Q6E8CYWV.W6V/E9XRW8V8.H5R/gest..tion_fc8add938e35284e_0000.0001_a2d7162722ad b1a3/Microsoft.Office.Interop.Excel.DLL

--
-La Inspiracion Existe, Pero tiene que encontrarte Trabajando-
Pablo Picasso
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convertion of Star Office documents to Microsoft Office SJM Excel Discussion (Misc queries) 3 July 30th 08 05:29 AM
Microsoft Office Excel (2007) Not enough system resources to displaycompletely [email protected] Excel Discussion (Misc queries) 6 July 21st 08 07:50 PM
How to activate my Microsoft 2003 system reject product key Setup Setting up and Configuration of Excel 2 January 31st 06 07:48 PM
Microsoft should put operating system on hardware not software Greg Weller Excel Discussion (Misc queries) 0 September 15th 05 05:11 AM
Visual Studio Tools for Microsoft Office System 2003 Regina Rodler Excel Programming 2 March 8th 05 01:34 PM


All times are GMT +1. The time now is 10:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"