01.
Public
Oxl
As
Excel.Application
02.
Public
Owb
As
Excel.Workbook
03.
Public
OSheet
As
Excel.Worksheet
04.
05.
Imports
Microsoft.Office.Core
06.
Imports
System.IO
07.
08.
Call
Kill_Process()
09.
Dim
File_Name
As
String
=
"บาร์โค๊ตรหัส "
& TxtWord.Text & TxtStart.Text &
"-"
& TxtWord.Text & TxtFinish.Text
10.
Oxl = CreateObject(
"Excel.Application"
)
11.
Dim
A = Application.StartupPath &
"\barcode\collection\"
12.
FileCopy(Application.StartupPath &
"\barcode\original\BarCode.xls"
, A & File_Name &
".xls"
)
13.
Owb = Oxl.Workbooks.Open(A & File_Name &
".xls"
)//
Error
Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
14.
Oxl.Visible =
True
15.
16.
Dim
BarCode
As
String
:
Dim
Word
As
String
=
Nothing
17.
Dim
i, Start, Finish, Count, Colum, Row
As
Integer
18.
Start = Val(TxtStart.Text) - 1 : Finish = Val(TxtFinish.Text) - 1
19.
Count = Start : Colum = 1 : Row = 0
20.
OSheet = Owb.ActiveSheet
21.
For
i = Start
To
Finish
22.
Count += 1
23.
BarCode = TxtWord.Text &
String
.Format(
"{1:000000}"
,
""
, Count)
24.
25.
Row += 1
26.
If
Row = 12
Then
27.
Colum += 1 : Row = 1
28.
End
If
29.
With
OSheet
30.
.Cells(Colum, Row).Value = BarCode
31.
.Cells(Colum, Row).Borders(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlLineStyle.xlContinuous
32.
.Cells(Colum, Row).Borders(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlContinuous
33.
.Cells(Colum, Row).Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlContinuous
34.
.Cells(Colum, Row).Borders(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlContinuous
35.
End
With
36.
Next
37.
Count = 0 : Colum = 0 : Row = 0