I’m trying to better than I was yesterday

Write to Excel #3

trutra863 Avatar
Sub WriteExcel_3(ByVal IndexMachine, ByVal IndexShift, ByVal ManualReport)
On Error Resume Next
'************************************************************************************************************************************
	Dim FolderLog
	FolderLog="C:\NIK_DATA" 
	Dim content
	Dim fso,Des_Folder_Name
	Set fso = CreateObject("Scripting.FileSystemObject")
	SmartTags("ReportStatus")=Now() & " : Check time for report..."
'************************************************************************************************************************************
	Dim ngay,gio, shift,dbindex
	Dim ngay2,gio2
	ngay = Now
	ngay2=ngay
	gio= Hour(Now)
	Dim row_head
	
	row_head=True
	
	shift=IndexShift  
	
	If IndexShift<1 Then				' neu shift = 0 - Current
		dbindex=0
		shift=2
		If gio>=7 And gio < 19 Then					'shif 1 ngay hom nay
			shift=1
		Else
			If gio < 7 Then					' neu gio nho hon 7 thì thuoc ca 2 ngay hom truoc
				ngay2=DateAdd("d",-1,ngay)	' tru ngay di 1
			End If
		End If
	Else
		If IndexShift<2 Then        		' neu shift = 1 - Ca 1 của ngày
			If gio < 19 Then					' neu gio nho hon 19 thì thuoc ca 1 ngay hom truoc
				ngay2=DateAdd("d",-1,ngay)	' tru ngay di 1
			End If
			shift=1
			dbindex=3
		Else								'Neu shift = 2 - Ca 2 của ngày
			If gio >= 7 Or gio <=23 Then	' neu gio >= 7 và  <= thì du lieu la cua ngay hom truoc
				ngay2=DateAdd("d",-1,ngay)	' tru ngay di 1
			Else
				If gio < 7 Then	' neu gio nho hon 7 thi du lieu la cua 2 ngay truoc
				ngay2=DateAdd("d",-2,ngay)	' tru ngay di 2
			Else
				
			End If
			End If
			shift=2	
			dbindex=4
		End If
	End If
'************************************************************************************************************************************
''***************************Kiem Tra file bao cao và copy form*******************************
	SmartTags("ReportStatus")=Now() & " : Check file for report."
	
	If ManualReport > 0 Then
		Des_Folder_Name = "C:\MANUAL_REPORT" 
		If Not fso.FolderExists(Des_Folder_Name) Then
     			fso.CreateFolder (Des_Folder_Name)
		End If
	Else
		Des_Folder_Name = CreateFolder (ngay2)
	End If
	
	
	
	If Des_Folder_Name="" Then
		ShowSystemAlarm "Report folder is null"
		Exit Sub
	Else
		
		Des_Folder_Name=Des_Folder_Name & "\DAILY_REPORT_" & Year(ngay2) & Month(ngay2) & Day(ngay2) & "_" & shift & ".xlsx"
	End If
	
	Dim SourceFile 
	SourceFile="C:\REPORT_DATA\Form\Form.xlsx"
	
	If Not fso.FileExists(SourceFile) Then
    	content="Report --- File Checking: Not exist form report file."
		LogFile FolderLog,"NikLog_" & Year(Now)& "_" & Month(Now) & Day(Now)& ".txt", content
		ShowSystemAlarm content
		Exit Sub
	Else
		If fso.FileExists(Des_Folder_Name)=False Then	
			fso.CopyFile SourceFile, Des_Folder_Name
		Else
			fso.GetFile(Des_Folder_Name).Attributes =0
		End If
	End If
'************************************************************************************************************************************
'************************************thuc hien ghi du lieu vao file*********************************************8
	
	SmartTags("ReportStatus")=Now() & " : Writing machine " & SmartTags("IndexMachine") & " data to report file..."
	
	Dim objExcelApp,objWorksheet,objWorksheetData,row_index
	Set objExcelApp = CreateObject("Excel.Application")
	objExcelApp.Visible = False
	objExcelApp.Workbooks.Open Des_Folder_Name

	Set objWorksheet = objExcelApp.Worksheets(1)
	
	row_index =  SmartTags("Row_Index_1")
	
	With objWorksheet
		.Cells(2,2).value = ngay2
		
		Dim partNo1, partNo2

		partNo1=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{1}_PART_NO_1"),_
										SmartTags("Press_REPORT_" & dbindex & "{1}_PART_NO_2"),_
										SmartTags("Press_REPORT_" & dbindex & "{1}_PART_NO_3"),_
										SmartTags("Press_REPORT_" & dbindex & "{1}_PART_NO_4"),_
										SmartTags("Press_REPORT_" & dbindex & "{1}_PART_NO_5"))
		partNo2=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{1}_PART_NO_6"),_
										SmartTags("Press_REPORT_" & dbindex & "{1}_PART_NO_7"),_
										SmartTags("Press_REPORT_" & dbindex & "{1}_PART_NO_8"),_
										SmartTags("Press_REPORT_" & dbindex & "{1}_PART_NO_9"),_
										SmartTags("Press_REPORT_" & dbindex & "{1}_PART_NO_10"))
		If (Trim(partNo1)<>"" Or Trim(partNo2)<>"") Then
			.Cells(row_index,1).value = "shift"
			.Cells(row_index,2).value = IndexMachine
			.Cells(row_index,3).value = partNo1& partNo2
			.Cells(row_index,4).value = SmartTags("Press_REPORT_" & dbindex & "{1}_START_HH")
			.Cells(row_index,5).value = SmartTags("Press_REPORT_" & dbindex & "{1}_START_MM")
			.Cells(row_index,6).value = SmartTags("Press_REPORT_" & dbindex & "{1}_END_HH")
			.Cells(row_index,7).value = SmartTags("Press_REPORT_" & dbindex & "{1}_END_MM")
			.Cells(row_index,8).value = SmartTags("Press_REPORT_" & dbindex & "{1}_QTY_OK")
			.Cells(row_index,9).value = SmartTags("Press_REPORT_" & dbindex & "{1}_QTY_NG")
			.Cells(row_index,10).value =SmartTags("Press_REPORT_" & dbindex & "{1}_RUN")
			.Cells(row_index,11).value =SmartTags("Press_REPORT_" & dbindex & "{1}_UNKNOWN")
			.Cells(row_index,12).value =SmartTags("Press_REPORT_" & dbindex & "{1}_RUN_UNKNOWN")
			.Cells(row_index,13).value =SmartTags("Press_REPORT_" & dbindex & "{1}_SETUP905")
			.Cells(row_index,14).value =SmartTags("Press_REPORT_" & dbindex & "{1}_SCHEDULE906")
			.Cells(row_index,15).value =SmartTags("Press_REPORT_" & dbindex & "{1}_SAMPLE902")
			.Cells(row_index,16).value = SmartTags("Press_REPORT_" & dbindex & "{1}_DOWNTIME")
			
			If row_head Then
				.Cells(row_index,1).Interior.ColorIndex = 35
				.Cells(row_index,2).Interior.ColorIndex = 35
				.Cells(row_index,3).Interior.ColorIndex = 35
				.Cells(row_index,4).Interior.ColorIndex = 35
				.Cells(row_index,5).Interior.ColorIndex = 35
				.Cells(row_index,6).Interior.ColorIndex = 35
				.Cells(row_index,7).Interior.ColorIndex = 35
				.Cells(row_index,8).Interior.ColorIndex = 35
				.Cells(row_index,9).Interior.ColorIndex = 35
				.Cells(row_index,10).Interior.ColorIndex = 35
				.Cells(row_index,11).Interior.ColorIndex = 35
				.Cells(row_index,12).Interior.ColorIndex = 35
				.Cells(row_index,13).Interior.ColorIndex = 35
				.Cells(row_index,14).Interior.ColorIndex = 35
				.Cells(row_index,15).Interior.ColorIndex = 35
				.Cells(row_index,16).Interior.ColorIndex = 35
				
				row_head=False
			End If
			row_index = row_index +1
		End If
		partNo1=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{2}_PART_NO_1"),_
										SmartTags("Press_REPORT_" & dbindex & "{2}_PART_NO_2"),_
										SmartTags("Press_REPORT_" & dbindex & "{2}_PART_NO_3"),_
										SmartTags("Press_REPORT_" & dbindex & "{2}_PART_NO_4"),_
										SmartTags("Press_REPORT_" & dbindex & "{2}_PART_NO_5"))
		partNo2=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{2}_PART_NO_6"),_
										SmartTags("Press_REPORT_" & dbindex & "{2}_PART_NO_7"),_
										SmartTags("Press_REPORT_" & dbindex & "{2}_PART_NO_8"),_
										SmartTags("Press_REPORT_" & dbindex & "{2}_PART_NO_9"),_
										SmartTags("Press_REPORT_" & dbindex & "{2}_PART_NO_10"))
		If (Trim(partNo1)<>"" Or Trim(partNo2)<>"") Then
			.Cells(row_index,1).value = "shift2"
			.Cells(row_index,2).value = IndexMachine
			.Cells(row_index,3).value = partNo1& partNo2
			.Cells(row_index,4).value = SmartTags("Press_REPORT_" & dbindex & "{2}_START_HH")
			.Cells(row_index,5).value = SmartTags("Press_REPORT_" & dbindex & "{2}_START_MM")
			.Cells(row_index,6).value = SmartTags("Press_REPORT_" & dbindex & "{2}_END_HH")
			.Cells(row_index,7).value = SmartTags("Press_REPORT_" & dbindex & "{2}_END_MM")
			.Cells(row_index,8).value = SmartTags("Press_REPORT_" & dbindex & "{2}_QTY_OK")
			.Cells(row_index,9).value = SmartTags("Press_REPORT_" & dbindex & "{2}_QTY_NG")
			.Cells(row_index,10).value =SmartTags("Press_REPORT_" & dbindex & "{2}_RUN")
			.Cells(row_index,11).value =SmartTags("Press_REPORT_" & dbindex & "{2}_UNKNOWN")
			.Cells(row_index,12).value =SmartTags("Press_REPORT_" & dbindex & "{2}_RUN_UNKNOWN")
			.Cells(row_index,13).value =SmartTags("Press_REPORT_" & dbindex & "{2}_SETUP905")
			.Cells(row_index,14).value =SmartTags("Press_REPORT_" & dbindex & "{2}_SCHEDULE906")
			.Cells(row_index,15).value =SmartTags("Press_REPORT_" & dbindex & "{2}_SAMPLE902")
			.Cells(row_index,16).value = SmartTags("Press_REPORT_" & dbindex & "{2}_DOWNTIME")
			If row_head Then
				.Cells(row_index,1).Interior.ColorIndex = 35
				.Cells(row_index,2).Interior.ColorIndex = 35
				.Cells(row_index,3).Interior.ColorIndex = 35
				.Cells(row_index,4).Interior.ColorIndex = 35
				.Cells(row_index,5).Interior.ColorIndex = 35
				.Cells(row_index,6).Interior.ColorIndex = 35
				.Cells(row_index,7).Interior.ColorIndex = 35
				.Cells(row_index,8).Interior.ColorIndex = 35
				.Cells(row_index,9).Interior.ColorIndex = 35
				.Cells(row_index,10).Interior.ColorIndex = 35
				.Cells(row_index,11).Interior.ColorIndex = 35
				.Cells(row_index,12).Interior.ColorIndex = 35
				.Cells(row_index,13).Interior.ColorIndex = 35
				.Cells(row_index,14).Interior.ColorIndex = 35
				.Cells(row_index,15).Interior.ColorIndex = 35
				.Cells(row_index,16).Interior.ColorIndex = 35
				
				row_head=False
			End If
			row_index = row_index +1
		End If
		partNo1=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{3}_PART_NO_1"),_
										SmartTags("Press_REPORT_" & dbindex & "{3}_PART_NO_2"),_
										SmartTags("Press_REPORT_" & dbindex & "{3}_PART_NO_3"),_
										SmartTags("Press_REPORT_" & dbindex & "{3}_PART_NO_4"),_
										SmartTags("Press_REPORT_" & dbindex & "{3}_PART_NO_5"))
		partNo2=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{3}_PART_NO_6"),_
										SmartTags("Press_REPORT_" & dbindex & "{3}_PART_NO_7"),_
										SmartTags("Press_REPORT_" & dbindex & "{3}_PART_NO_8"),_
										SmartTags("Press_REPORT_" & dbindex & "{3}_PART_NO_9"),_
										SmartTags("Press_REPORT_" & dbindex & "{3}_PART_NO_10"))
		If (Trim(partNo1)<>"" Or Trim(partNo2)<>"") Then
			.Cells(row_index,1).value = shift
			.Cells(row_index,2).value = IndexMachine
			.Cells(row_index,3).value = partNo1& partNo2
			.Cells(row_index,4).value = SmartTags("Press_REPORT_" & dbindex & "{3}_START_HH")
			.Cells(row_index,5).value = SmartTags("Press_REPORT_" & dbindex & "{3}_START_MM")
			.Cells(row_index,6).value = SmartTags("Press_REPORT_" & dbindex & "{3}_END_HH")
			.Cells(row_index,7).value = SmartTags("Press_REPORT_" & dbindex & "{3}_END_MM")
			.Cells(row_index,8).value = SmartTags("Press_REPORT_" & dbindex & "{3}_QTY_OK")
			.Cells(row_index,9).value = SmartTags("Press_REPORT_" & dbindex & "{3}_QTY_NG")
			.Cells(row_index,10).value =SmartTags("Press_REPORT_" & dbindex & "{3}_RUN")
			.Cells(row_index,11).value =SmartTags("Press_REPORT_" & dbindex & "{3}_UNKNOWN")
			.Cells(row_index,12).value =SmartTags("Press_REPORT_" & dbindex & "{3}_RUN_UNKNOWN")
			.Cells(row_index,13).value =SmartTags("Press_REPORT_" & dbindex & "{3}_SETUP905")
			.Cells(row_index,14).value =SmartTags("Press_REPORT_" & dbindex & "{3}_SCHEDULE906")
			.Cells(row_index,15).value =SmartTags("Press_REPORT_" & dbindex & "{3}_SAMPLE902")
			.Cells(row_index,16).value = SmartTags("Press_REPORT_" & dbindex & "{3}_DOWNTIME")
			
			If row_head Then
				.Cells(row_index,1).Interior.ColorIndex = 35
				.Cells(row_index,2).Interior.ColorIndex = 35
				.Cells(row_index,3).Interior.ColorIndex = 35
				.Cells(row_index,4).Interior.ColorIndex = 35
				.Cells(row_index,5).Interior.ColorIndex = 35
				.Cells(row_index,6).Interior.ColorIndex = 35
				.Cells(row_index,7).Interior.ColorIndex = 35
				.Cells(row_index,8).Interior.ColorIndex = 35
				.Cells(row_index,9).Interior.ColorIndex = 35
				.Cells(row_index,10).Interior.ColorIndex = 35
				.Cells(row_index,11).Interior.ColorIndex = 35
				.Cells(row_index,12).Interior.ColorIndex = 35
				.Cells(row_index,13).Interior.ColorIndex = 35
				.Cells(row_index,14).Interior.ColorIndex = 35
				.Cells(row_index,15).Interior.ColorIndex = 35
				.Cells(row_index,16).Interior.ColorIndex = 35
				
				row_head=False
			End If
			row_index = row_index +1
		End If
		partNo1=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{4}_PART_NO_1"),_
										SmartTags("Press_REPORT_" & dbindex & "{4}_PART_NO_2"),_
										SmartTags("Press_REPORT_" & dbindex & "{4}_PART_NO_3"),_
										SmartTags("Press_REPORT_" & dbindex & "{4}_PART_NO_4"),_
										SmartTags("Press_REPORT_" & dbindex & "{4}_PART_NO_5"))
		partNo2=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{4}_PART_NO_6"),_
										SmartTags("Press_REPORT_" & dbindex & "{4}_PART_NO_7"),_
										SmartTags("Press_REPORT_" & dbindex & "{4}_PART_NO_8"),_
										SmartTags("Press_REPORT_" & dbindex & "{4}_PART_NO_9"),_
										SmartTags("Press_REPORT_" & dbindex & "{4}_PART_NO_10"))
		If (Trim(partNo1)<>"" Or Trim(partNo2)<>"") Then
			.Cells(row_index,1).value = shift
			.Cells(row_index,2).value = IndexMachine
			.Cells(row_index,3).value = partNo1& partNo2
			.Cells(row_index,4).value = SmartTags("Press_REPORT_" & dbindex & "{4}_START_HH")
			.Cells(row_index,5).value = SmartTags("Press_REPORT_" & dbindex & "{4}_START_MM")
			.Cells(row_index,6).value = SmartTags("Press_REPORT_" & dbindex & "{4}_END_HH")
			.Cells(row_index,7).value = SmartTags("Press_REPORT_" & dbindex & "{4}_END_MM")
			.Cells(row_index,8).value = SmartTags("Press_REPORT_" & dbindex & "{4}_QTY_OK")
			.Cells(row_index,9).value = SmartTags("Press_REPORT_" & dbindex & "{4}_QTY_NG")
			.Cells(row_index,10).value =SmartTags("Press_REPORT_" & dbindex & "{4}_RUN")
			.Cells(row_index,11).value =SmartTags("Press_REPORT_" & dbindex & "{4}_UNKNOWN")
			.Cells(row_index,12).value =SmartTags("Press_REPORT_" & dbindex & "{4}_RUN_UNKNOWN")
			.Cells(row_index,13).value =SmartTags("Press_REPORT_" & dbindex & "{4}_SETUP905")
			.Cells(row_index,14).value =SmartTags("Press_REPORT_" & dbindex & "{4}_SCHEDULE906")
			.Cells(row_index,15).value =SmartTags("Press_REPORT_" & dbindex & "{4}_SAMPLE902")
			.Cells(row_index,16).value = SmartTags("Press_REPORT_" & dbindex & "{4}_DOWNTIME")
			
			If row_head Then
				.Cells(row_index,1).Interior.ColorIndex = 35
				.Cells(row_index,2).Interior.ColorIndex = 35
				.Cells(row_index,3).Interior.ColorIndex = 35
				.Cells(row_index,4).Interior.ColorIndex = 35
				.Cells(row_index,5).Interior.ColorIndex = 35
				.Cells(row_index,6).Interior.ColorIndex = 35
				.Cells(row_index,7).Interior.ColorIndex = 35
				.Cells(row_index,8).Interior.ColorIndex = 35
				.Cells(row_index,9).Interior.ColorIndex = 35
				.Cells(row_index,10).Interior.ColorIndex = 35
				.Cells(row_index,11).Interior.ColorIndex = 35
				.Cells(row_index,12).Interior.ColorIndex = 35
				.Cells(row_index,13).Interior.ColorIndex = 35
				.Cells(row_index,14).Interior.ColorIndex = 35
				.Cells(row_index,15).Interior.ColorIndex = 35
				.Cells(row_index,16).Interior.ColorIndex = 35
				
				row_head=False
			End If
			row_index = row_index +1
		End If
		partNo1=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{5}_PART_NO_1"),_
										SmartTags("Press_REPORT_" & dbindex & "{5}_PART_NO_2"),_
										SmartTags("Press_REPORT_" & dbindex & "{5}_PART_NO_3"),_
										SmartTags("Press_REPORT_" & dbindex & "{5}_PART_NO_4"),_
										SmartTags("Press_REPORT_" & dbindex & "{5}_PART_NO_5"))
		partNo2=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{5}_PART_NO_6"),_
										SmartTags("Press_REPORT_" & dbindex & "{5}_PART_NO_7"),_
										SmartTags("Press_REPORT_" & dbindex & "{5}_PART_NO_8"),_
										SmartTags("Press_REPORT_" & dbindex & "{5}_PART_NO_9"),_
										SmartTags("Press_REPORT_" & dbindex & "{5}_PART_NO_10"))
		If (Trim(partNo1)<>"" Or Trim(partNo2)<>"") Then
			.Cells(row_index,1).value = shift
			.Cells(row_index,2).value = IndexMachine
			.Cells(row_index,3).value = partNo1& partNo2
			.Cells(row_index,4).value = SmartTags("Press_REPORT_" & dbindex & "{5}_START_HH")
			.Cells(row_index,5).value = SmartTags("Press_REPORT_" & dbindex & "{5}_START_MM")
			.Cells(row_index,6).value = SmartTags("Press_REPORT_" & dbindex & "{5}_END_HH")
			.Cells(row_index,7).value = SmartTags("Press_REPORT_" & dbindex & "{5}_END_MM")
			.Cells(row_index,8).value = SmartTags("Press_REPORT_" & dbindex & "{5}_QTY_OK")
			.Cells(row_index,9).value = SmartTags("Press_REPORT_" & dbindex & "{5}_QTY_NG")
			.Cells(row_index,10).value =SmartTags("Press_REPORT_" & dbindex & "{5}_RUN")
			.Cells(row_index,11).value =SmartTags("Press_REPORT_" & dbindex & "{5}_UNKNOWN")
			.Cells(row_index,12).value =SmartTags("Press_REPORT_" & dbindex & "{5}_RUN_UNKNOWN")
			.Cells(row_index,13).value =SmartTags("Press_REPORT_" & dbindex & "{5}_SETUP905")
			.Cells(row_index,14).value =SmartTags("Press_REPORT_" & dbindex & "{5}_SCHEDULE906")
			.Cells(row_index,15).value =SmartTags("Press_REPORT_" & dbindex & "{5}_SAMPLE902")
			.Cells(row_index,16).value = SmartTags("Press_REPORT_" & dbindex & "{5}_DOWNTIME")
			If row_head Then
				.Cells(row_index,1).Interior.ColorIndex = 35
				.Cells(row_index,2).Interior.ColorIndex = 35
				.Cells(row_index,3).Interior.ColorIndex = 35
				.Cells(row_index,4).Interior.ColorIndex = 35
				.Cells(row_index,5).Interior.ColorIndex = 35
				.Cells(row_index,6).Interior.ColorIndex = 35
				.Cells(row_index,7).Interior.ColorIndex = 35
				.Cells(row_index,8).Interior.ColorIndex = 35
				.Cells(row_index,9).Interior.ColorIndex = 35
				.Cells(row_index,10).Interior.ColorIndex = 35
				.Cells(row_index,11).Interior.ColorIndex = 35
				.Cells(row_index,12).Interior.ColorIndex = 35
				.Cells(row_index,13).Interior.ColorIndex = 35
				.Cells(row_index,14).Interior.ColorIndex = 35
				.Cells(row_index,15).Interior.ColorIndex = 35
				.Cells(row_index,16).Interior.ColorIndex = 35
				
				row_head=False
			End If
			row_index = row_index +1
		End If
		partNo1=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{6}_PART_NO_1"),_
										SmartTags("Press_REPORT_" & dbindex & "{6}_PART_NO_2"),_
										SmartTags("Press_REPORT_" & dbindex & "{6}_PART_NO_3"),_
										SmartTags("Press_REPORT_" & dbindex & "{6}_PART_NO_4"),_
										SmartTags("Press_REPORT_" & dbindex & "{6}_PART_NO_5"))
		partNo2=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{6}_PART_NO_6"),_
										SmartTags("Press_REPORT_" & dbindex & "{6}_PART_NO_7"),_
										SmartTags("Press_REPORT_" & dbindex & "{6}_PART_NO_8"),_
										SmartTags("Press_REPORT_" & dbindex & "{6}_PART_NO_9"),_
										SmartTags("Press_REPORT_" & dbindex & "{6}_PART_NO_10"))
		If (Trim(partNo1)<>"" Or Trim(partNo2)<>"") Then
			.Cells(row_index,1).value = shift
			.Cells(row_index,2).value = IndexMachine
			.Cells(row_index,3).value = partNo1& partNo2
			.Cells(row_index,4).value = SmartTags("Press_REPORT_" & dbindex & "{6}_START_HH")
			.Cells(row_index,5).value = SmartTags("Press_REPORT_" & dbindex & "{6}_START_MM")
			.Cells(row_index,6).value = SmartTags("Press_REPORT_" & dbindex & "{6}_END_HH")
			.Cells(row_index,7).value = SmartTags("Press_REPORT_" & dbindex & "{6}_END_MM")
			.Cells(row_index,8).value = SmartTags("Press_REPORT_" & dbindex & "{6}_QTY_OK")
			.Cells(row_index,9).value = SmartTags("Press_REPORT_" & dbindex & "{6}_QTY_NG")
			.Cells(row_index,10).value =SmartTags("Press_REPORT_" & dbindex & "{6}_RUN")
			.Cells(row_index,11).value =SmartTags("Press_REPORT_" & dbindex & "{6}_UNKNOWN")
			.Cells(row_index,12).value =SmartTags("Press_REPORT_" & dbindex & "{6}_RUN_UNKNOWN")
			.Cells(row_index,13).value =SmartTags("Press_REPORT_" & dbindex & "{6}_SETUP905")
			.Cells(row_index,14).value =SmartTags("Press_REPORT_" & dbindex & "{6}_SCHEDULE906")
			.Cells(row_index,15).value =SmartTags("Press_REPORT_" & dbindex & "{6}_SAMPLE902")
			.Cells(row_index,16).value = SmartTags("Press_REPORT_" & dbindex & "{6}_DOWNTIME")
			If row_head Then
				.Cells(row_index,1).Interior.ColorIndex = 35
				.Cells(row_index,2).Interior.ColorIndex = 35
				.Cells(row_index,3).Interior.ColorIndex = 35
				.Cells(row_index,4).Interior.ColorIndex = 35
				.Cells(row_index,5).Interior.ColorIndex = 35
				.Cells(row_index,6).Interior.ColorIndex = 35
				.Cells(row_index,7).Interior.ColorIndex = 35
				.Cells(row_index,8).Interior.ColorIndex = 35
				.Cells(row_index,9).Interior.ColorIndex = 35
				.Cells(row_index,10).Interior.ColorIndex = 35
				.Cells(row_index,11).Interior.ColorIndex = 35
				.Cells(row_index,12).Interior.ColorIndex = 35
				.Cells(row_index,13).Interior.ColorIndex = 35
				.Cells(row_index,14).Interior.ColorIndex = 35
				.Cells(row_index,15).Interior.ColorIndex = 35
				.Cells(row_index,16).Interior.ColorIndex = 35
				
				row_head=False
			End If
			row_index = row_index +1
		End If
		partNo1=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{7}_PART_NO_1"),_
										SmartTags("Press_REPORT_" & dbindex & "{7}_PART_NO_2"),_
										SmartTags("Press_REPORT_" & dbindex & "{7}_PART_NO_3"),_
										SmartTags("Press_REPORT_" & dbindex & "{7}_PART_NO_4"),_
										SmartTags("Press_REPORT_" & dbindex & "{7}_PART_NO_5"))
		partNo2=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{7}_PART_NO_6"),_
										SmartTags("Press_REPORT_" & dbindex & "{7}_PART_NO_7"),_
										SmartTags("Press_REPORT_" & dbindex & "{7}_PART_NO_8"),_
										SmartTags("Press_REPORT_" & dbindex & "{7}_PART_NO_9"),_
										SmartTags("Press_REPORT_" & dbindex & "{7}_PART_NO_10"))
		If (Trim(partNo1)<>"" Or Trim(partNo2)<>"") Then
			.Cells(row_index,1).value = shift
			.Cells(row_index,2).value = IndexMachine
			.Cells(row_index,3).value = partNo1& partNo2
			.Cells(row_index,4).value = SmartTags("Press_REPORT_" & dbindex & "{7}_START_HH")
			.Cells(row_index,5).value = SmartTags("Press_REPORT_" & dbindex & "{7}_START_MM")
			.Cells(row_index,6).value = SmartTags("Press_REPORT_" & dbindex & "{7}_END_HH")
			.Cells(row_index,7).value = SmartTags("Press_REPORT_" & dbindex & "{7}_END_MM")
			.Cells(row_index,8).value = SmartTags("Press_REPORT_" & dbindex & "{7}_QTY_OK")
			.Cells(row_index,9).value = SmartTags("Press_REPORT_" & dbindex & "{7}_QTY_NG")
			.Cells(row_index,10).value =SmartTags("Press_REPORT_" & dbindex & "{7}_RUN")
			.Cells(row_index,11).value =SmartTags("Press_REPORT_" & dbindex & "{7}_UNKNOWN")
			.Cells(row_index,12).value =SmartTags("Press_REPORT_" & dbindex & "{7}_RUN_UNKNOWN")
			.Cells(row_index,13).value =SmartTags("Press_REPORT_" & dbindex & "{7}_SETUP905")
			.Cells(row_index,14).value =SmartTags("Press_REPORT_" & dbindex & "{7}_SCHEDULE906")
			.Cells(row_index,15).value =SmartTags("Press_REPORT_" & dbindex & "{7}_SAMPLE902")
			.Cells(row_index,16).value = SmartTags("Press_REPORT_" & dbindex & "{7}_DOWNTIME")
			If row_head Then
				.Cells(row_index,1).Interior.ColorIndex = 35
				.Cells(row_index,2).Interior.ColorIndex = 35
				.Cells(row_index,3).Interior.ColorIndex = 35
				.Cells(row_index,4).Interior.ColorIndex = 35
				.Cells(row_index,5).Interior.ColorIndex = 35
				.Cells(row_index,6).Interior.ColorIndex = 35
				.Cells(row_index,7).Interior.ColorIndex = 35
				.Cells(row_index,8).Interior.ColorIndex = 35
				.Cells(row_index,9).Interior.ColorIndex = 35
				.Cells(row_index,10).Interior.ColorIndex = 35
				.Cells(row_index,11).Interior.ColorIndex = 35
				.Cells(row_index,12).Interior.ColorIndex = 35
				.Cells(row_index,13).Interior.ColorIndex = 35
				.Cells(row_index,14).Interior.ColorIndex = 35
				.Cells(row_index,15).Interior.ColorIndex = 35
				.Cells(row_index,16).Interior.ColorIndex = 35
				
				row_head=False
			End If
			row_index = row_index +1
		End If
		partNo1=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{8}_PART_NO_1"),_
										SmartTags("Press_REPORT_" & dbindex & "{8}_PART_NO_2"),_
										SmartTags("Press_REPORT_" & dbindex & "{8}_PART_NO_3"),_
										SmartTags("Press_REPORT_" & dbindex & "{8}_PART_NO_4"),_
										SmartTags("Press_REPORT_" & dbindex & "{8}_PART_NO_5"))
		partNo2=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{8}_PART_NO_6"),_
										SmartTags("Press_REPORT_" & dbindex & "{8}_PART_NO_7"),_
										SmartTags("Press_REPORT_" & dbindex & "{8}_PART_NO_8"),_
										SmartTags("Press_REPORT_" & dbindex & "{8}_PART_NO_9"),_
										SmartTags("Press_REPORT_" & dbindex & "{8}_PART_NO_10"))
		If (Trim(partNo1)<>"" Or Trim(partNo2)<>"") Then
			.Cells(row_index,1).value = shift
			.Cells(row_index,2).value = IndexMachine
			.Cells(row_index,3).value = partNo1& partNo2
			.Cells(row_index,4).value = SmartTags("Press_REPORT_" & dbindex & "{8}_START_HH")
			.Cells(row_index,5).value = SmartTags("Press_REPORT_" & dbindex & "{8}_START_MM")
			.Cells(row_index,6).value = SmartTags("Press_REPORT_" & dbindex & "{8}_END_HH")
			.Cells(row_index,7).value = SmartTags("Press_REPORT_" & dbindex & "{8}_END_MM")
			.Cells(row_index,8).value = SmartTags("Press_REPORT_" & dbindex & "{8}_QTY_OK")
			.Cells(row_index,9).value = SmartTags("Press_REPORT_" & dbindex & "{8}_QTY_NG")
			.Cells(row_index,10).value =SmartTags("Press_REPORT_" & dbindex & "{8}_RUN")
			.Cells(row_index,11).value =SmartTags("Press_REPORT_" & dbindex & "{8}_UNKNOWN")
			.Cells(row_index,12).value =SmartTags("Press_REPORT_" & dbindex & "{8}_RUN_UNKNOWN")
			.Cells(row_index,13).value =SmartTags("Press_REPORT_" & dbindex & "{8}_SETUP905")
			.Cells(row_index,14).value =SmartTags("Press_REPORT_" & dbindex & "{8}_SCHEDULE906")
			.Cells(row_index,15).value =SmartTags("Press_REPORT_" & dbindex & "{8}_SAMPLE902")
			.Cells(row_index,16).value = SmartTags("Press_REPORT_" & dbindex & "{8}_DOWNTIME")
			If row_head Then
				.Cells(row_index,1).Interior.ColorIndex = 35
				.Cells(row_index,2).Interior.ColorIndex = 35
				.Cells(row_index,3).Interior.ColorIndex = 35
				.Cells(row_index,4).Interior.ColorIndex = 35
				.Cells(row_index,5).Interior.ColorIndex = 35
				.Cells(row_index,6).Interior.ColorIndex = 35
				.Cells(row_index,7).Interior.ColorIndex = 35
				.Cells(row_index,8).Interior.ColorIndex = 35
				.Cells(row_index,9).Interior.ColorIndex = 35
				.Cells(row_index,10).Interior.ColorIndex = 35
				.Cells(row_index,11).Interior.ColorIndex = 35
				.Cells(row_index,12).Interior.ColorIndex = 35
				.Cells(row_index,13).Interior.ColorIndex = 35
				.Cells(row_index,14).Interior.ColorIndex = 35
				.Cells(row_index,15).Interior.ColorIndex = 35
				.Cells(row_index,16).Interior.ColorIndex = 35
				
				row_head=False
			End If
			row_index = row_index +1
		End If
		partNo1=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{9}_PART_NO_1"),_
										SmartTags("Press_REPORT_" & dbindex & "{9}_PART_NO_2"),_
										SmartTags("Press_REPORT_" & dbindex & "{9}_PART_NO_3"),_
										SmartTags("Press_REPORT_" & dbindex & "{9}_PART_NO_4"),_
										SmartTags("Press_REPORT_" & dbindex & "{9}_PART_NO_5"))
		partNo2=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{9}_PART_NO_6"),_
										SmartTags("Press_REPORT_" & dbindex & "{9}_PART_NO_7"),_
										SmartTags("Press_REPORT_" & dbindex & "{9}_PART_NO_8"),_
										SmartTags("Press_REPORT_" & dbindex & "{9}_PART_NO_9"),_
										SmartTags("Press_REPORT_" & dbindex & "{9}_PART_NO_10"))
		If (Trim(partNo1)<>"" Or Trim(partNo2)<>"") Then
			.Cells(row_index,1).value = shift
			.Cells(row_index,2).value = IndexMachine
			.Cells(row_index,3).value = partNo1& partNo2
			.Cells(row_index,4).value = SmartTags("Press_REPORT_" & dbindex & "{9}_START_HH")
			.Cells(row_index,5).value = SmartTags("Press_REPORT_" & dbindex & "{9}_START_MM")
			.Cells(row_index,6).value = SmartTags("Press_REPORT_" & dbindex & "{9}_END_HH")
			.Cells(row_index,7).value = SmartTags("Press_REPORT_" & dbindex & "{9}_END_MM")
			.Cells(row_index,8).value = SmartTags("Press_REPORT_" & dbindex & "{9}_QTY_OK")
			.Cells(row_index,9).value = SmartTags("Press_REPORT_" & dbindex & "{9}_QTY_NG")
			.Cells(row_index,10).value =SmartTags("Press_REPORT_" & dbindex & "{9}_RUN")
			.Cells(row_index,11).value =SmartTags("Press_REPORT_" & dbindex & "{9}_UNKNOWN")
			.Cells(row_index,12).value =SmartTags("Press_REPORT_" & dbindex & "{9}_RUN_UNKNOWN")
			.Cells(row_index,13).value =SmartTags("Press_REPORT_" & dbindex & "{9}_SETUP905")
			.Cells(row_index,14).value =SmartTags("Press_REPORT_" & dbindex & "{9}_SCHEDULE906")
			.Cells(row_index,15).value =SmartTags("Press_REPORT_" & dbindex & "{9}_SAMPLE902")
			.Cells(row_index,16).value = SmartTags("Press_REPORT_" & dbindex & "{9}_DOWNTIME")
			If row_head Then
				.Cells(row_index,1).Interior.ColorIndex = 35
				.Cells(row_index,2).Interior.ColorIndex = 35
				.Cells(row_index,3).Interior.ColorIndex = 35
				.Cells(row_index,4).Interior.ColorIndex = 35
				.Cells(row_index,5).Interior.ColorIndex = 35
				.Cells(row_index,6).Interior.ColorIndex = 35
				.Cells(row_index,7).Interior.ColorIndex = 35
				.Cells(row_index,8).Interior.ColorIndex = 35
				.Cells(row_index,9).Interior.ColorIndex = 35
				.Cells(row_index,10).Interior.ColorIndex = 35
				.Cells(row_index,11).Interior.ColorIndex = 35
				.Cells(row_index,12).Interior.ColorIndex = 35
				.Cells(row_index,13).Interior.ColorIndex = 35
				.Cells(row_index,14).Interior.ColorIndex = 35
				.Cells(row_index,15).Interior.ColorIndex = 35
				.Cells(row_index,16).Interior.ColorIndex = 35
				
				row_head=False
			End If
			row_index = row_index +1
		End If
		partNo1=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{10}_PART_NO_1"),_
										SmartTags("Press_REPORT_" & dbindex & "{10}_PART_NO_2"),_
										SmartTags("Press_REPORT_" & dbindex & "{10}_PART_NO_3"),_
										SmartTags("Press_REPORT_" & dbindex & "{10}_PART_NO_4"),_
										SmartTags("Press_REPORT_" & dbindex & "{10}_PART_NO_5"))
		partNo2=ConvertArrayCharToString(SmartTags("Press_REPORT_" & dbindex & "{10}_PART_NO_6"),_
										SmartTags("Press_REPORT_" & dbindex & "{10}_PART_NO_7"),_
										SmartTags("Press_REPORT_" & dbindex & "{10}_PART_NO_8"),_
										SmartTags("Press_REPORT_" & dbindex & "{10}_PART_NO_9"),_
										SmartTags("Press_REPORT_" & dbindex & "{10}_PART_NO_10"))
		If (Trim(partNo1)<>"" Or Trim(partNo2)<>"") Then
			.Cells(row_index,1).value = shift
			.Cells(row_index,2).value = IndexMachine
			.Cells(row_index,3).value = partNo1& partNo2
			.Cells(row_index,4).value = SmartTags("Press_REPORT_" & dbindex & "{10}_START_HH")
			.Cells(row_index,5).value = SmartTags("Press_REPORT_" & dbindex & "{10}_START_MM")
			.Cells(row_index,6).value = SmartTags("Press_REPORT_" & dbindex & "{10}_END_HH")
			.Cells(row_index,7).value = SmartTags("Press_REPORT_" & dbindex & "{10}_END_MM")
			.Cells(row_index,8).value = SmartTags("Press_REPORT_" & dbindex & "{10}_QTY_OK")
			.Cells(row_index,9).value = SmartTags("Press_REPORT_" & dbindex & "{10}_QTY_NG")
			.Cells(row_index,10).value =SmartTags("Press_REPORT_" & dbindex & "{10}_RUN")
			.Cells(row_index,11).value =SmartTags("Press_REPORT_" & dbindex & "{10}_UNKNOWN")
			.Cells(row_index,12).value =SmartTags("Press_REPORT_" & dbindex & "{10}_RUN_UNKNOWN")
			.Cells(row_index,13).value =SmartTags("Press_REPORT_" & dbindex & "{10}_SETUP905")
			.Cells(row_index,14).value =SmartTags("Press_REPORT_" & dbindex & "{10}_SCHEDULE906")
			.Cells(row_index,15).value =SmartTags("Press_REPORT_" & dbindex & "{10}_SAMPLE902")
			.Cells(row_index,16).value = SmartTags("Press_REPORT_" & dbindex & "{10}_DOWNTIME")
			If row_head Then
				.Cells(row_index,1).Interior.ColorIndex = 35
				.Cells(row_index,2).Interior.ColorIndex = 35
				.Cells(row_index,3).Interior.ColorIndex = 35
				.Cells(row_index,4).Interior.ColorIndex = 35
				.Cells(row_index,5).Interior.ColorIndex = 35
				.Cells(row_index,6).Interior.ColorIndex = 35
				.Cells(row_index,7).Interior.ColorIndex = 35
				.Cells(row_index,8).Interior.ColorIndex = 35
				.Cells(row_index,9).Interior.ColorIndex = 35
				.Cells(row_index,10).Interior.ColorIndex = 35
				.Cells(row_index,11).Interior.ColorIndex = 35
				.Cells(row_index,12).Interior.ColorIndex = 35
				.Cells(row_index,13).Interior.ColorIndex = 35
				.Cells(row_index,14).Interior.ColorIndex = 35
				.Cells(row_index,15).Interior.ColorIndex = 35
				.Cells(row_index,16).Interior.ColorIndex = 35
				
				row_head=False
			End If
			row_index = row_index +1
		End If
	End With
		
	SmartTags("Row_Index_1")	=	row_index 
	
	'ShowSystemAlarm "Report --- Save report file."
	objExcelApp.ActiveWorkbook.Save
	objExcelApp.Workbooks.Close
	objExcelApp.Quit
	Set objExcelApp = Nothing 

	Dim f
	Set f = fso.GetFile(Des_Folder_Name)
	f.Attributes =1
	
	SmartTags("ReportStatus")=Now() & " : Done."
			
	If Err.Number<>0 Then
		content="WriteExcel: " & Err.Number &" - " & Err.Description 
		LogFile FolderLog,"NikLog_" & Year(Now)& "_" & Month(Now) & Day(Now)& ".txt", content
		SmartTags("ReportStatus")=""
		ShowSystemAlarm content
		Err.Clear
	End If
End Sub

Search

Latest Posts

Categories

I’m trying to better than I was yesterday