Question Display Excel Cell's in TextBoxes

Mr-HaXx

New member
Joined
Feb 3, 2011
Messages
3
Programming Experience
Beginner
Can someone help me with the following?

I currently have an application that shows information about several things in the company like email, schedule, and installations.
The Installations come from an Excel File that needs to be shown inside textboxes.
What i have now is:

VB.NET:
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'============================ Excel ============================[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] xl [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Application[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] xlsheet [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Worksheet[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] xlwbook [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Workbook[/SIZE]
[SIZE=2]xl = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.ApplicationClass[/SIZE]
[SIZE=2]xlwbook = xl.Workbooks.Open([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\\******\IT_SUPPORT$\01_ServiceDesk\01_ADMINISTRATION\Installations.xls"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], ReadOnly:=[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]xlsheet = xlwbook.Worksheets([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Bakel"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]xl.Visible = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][/COLOR][/SIZE]

Then i have to get each cell into an Dim like:

VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oRng1 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Range[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oRng2 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Range[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oRng3 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Range[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oRng4 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Range[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oRng5 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Range[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oRng6 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Range[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oRng7 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Range[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oRng8 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Range[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oRng9 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Excel.Range[/SIZE]
This goes on till oRng200
Then i set the Dim's as the Range like:
VB.NET:
[SIZE=2]oRng1 = xlsheet.Range([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"A2"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]oRng2 = xlsheet.Range([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"A3"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]oRng3 = xlsheet.Range([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"A4"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]oRng4 = xlsheet.Range([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"A5"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]oRng5 = xlsheet.Range([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"A6"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]oRng6 = xlsheet.Range([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"A7"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]oRng7 = xlsheet.Range([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"A8"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]oRng8 = xlsheet.Range([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"A9"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]oRng9 = xlsheet.Range([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"A10"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
Same here, this i have to set for 200 dim's
It then shows in:
VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oRng1.Value = 0 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]Prio_1.Hide()[/SIZE]
[SIZE=2]UserName1.Hide()[/SIZE]
[SIZE=2]Date1.Hide()[/SIZE]
[SIZE=2]Manager1.Hide()[/SIZE]
[SIZE=2]IR1.Hide()[/SIZE]
[SIZE=2]IS1.Hide()[/SIZE]
[SIZE=2]Status1.Hide()[/SIZE]
[SIZE=2]Details1.Hide()[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]Prio_1.Show()[/SIZE]
[SIZE=2]UserName1.Show()[/SIZE]
[SIZE=2]Date1.Show()[/SIZE]
[SIZE=2]Manager1.Show()[/SIZE]
[SIZE=2]IR1.Show()[/SIZE]
[SIZE=2]IS1.Show()[/SIZE]
[SIZE=2]Status1.Show()[/SIZE]
[SIZE=2]Details1.Show()[/SIZE]
[SIZE=2]Prio_1.Text = (oRng1.Value)[/SIZE]
[SIZE=2]UserName1.Text = (oRng21.Value)[/SIZE]
[SIZE=2]Date1.Text = (oRng141.Value)[/SIZE]
[SIZE=2]Manager1.Text = (oRng41.Value)[/SIZE]
[SIZE=2]IR1.Text = (oRng61.Value)[/SIZE]
[SIZE=2]IS1.Text = (oRng81.Value)[/SIZE]
[SIZE=2]Status1.Text = (oRng121.Value)[/SIZE]
[SIZE=2]Details1.Text = (oRng101.Value)[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[/COLOR][/SIZE]

that times 20 making it even bigger.
and everytime it wants to get another Range, it seems to re-open excel so i have placed this on the end of the script:
VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] proc [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Diagnostics.Process[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] proc [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Diagnostics.Process.GetProcessesByName([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"EXCEL"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]proc.Kill()[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[/COLOR][/SIZE]
Is there a way to make it easier?
 
Back
Top