-
Jul 29th, 2024, 09:54 AM
#1
Thread Starter
New Member
Excel Cell Read
Hi,
this code for read excel cell it's ok:
Code:
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles ButtonConverti.Click
Dim MyExcel As New Excel.Application
MyExcel.Workbooks.Open("C:\Users\Tony\Desktop\excel-vbnet\test.xlsx")
Dim cr As String
Dim r As Integer
'cr = "A37"
Label1.Text = MyExcel.Range(cr).Value
MyExcel.Visible = True
End Sub
End Class
Why in this way I have a error?
Code:
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles ButtonConverti.Click
Dim MyExcel As New Excel.Application
MyExcel.Workbooks.Open("C:\Users\Tony\Desktop\excel-vbnet\test.xlsx")
Dim cr As String
Dim r As Integer
'cr = "A37"
r = 37
cr = "A" + Str(r)
Label1.Text = MyExcel.Range(cr).Value
MyExcel.Visible = True
End Sub
End Class
This error:
System.Runtime.InteropServices.COMException non รจ stata gestita
ErrorCode=-2146827284
HResult=-2146827284
Message=Eccezione da HRESULT: 0x800A03EC
Source=Microsoft.Office.Interop.Excel
StackTrace:
in Microsoft.Office.Interop.Excel.ApplicationClass.get_Range(Object Cell1, Object Cell2)
in ferrari_excel.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\Tony\Desktop\excel-vbnet\ferrari_excel\ferrari_excel\Form1.vb:riga 57
in System.Windows.Forms.Control.OnClick(EventArgs e)
in System.Windows.Forms.Button.OnClick(EventArgs e)
in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
in System.Windows.Forms.Control.WndProc(Message& m)
in System.Windows.Forms.ButtonBase.WndProc(Message& m)
in System.Windows.Forms.Button.WndProc(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
in ferrari_excel.My.MyApplication.Main(String[] Args) in :riga 81
in System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
in System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
in System.Threading.ThreadHelper.ThreadStart()
InnerException:
-
Jul 29th, 2024, 11:43 AM
#2
Re: Excel Cell Read
Put a breakpoint on the line that starts with Label1.Text =. Look at cr.
One other thing, use & for concatenation, not +.
Last edited by dbasnett; Jul 30th, 2024 at 06:50 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|