• 목록
  • 아래로
  • 위로
  • 0
  • 임꺽
  • 조회 수 3481
Sub StatusSave()
       Set ExcelApp = CreateObject("Excel.Application")
       ' 파일이름을 생성한다.
       fFormName$ = "D:\냉매압축기\냉매압축기보고서양식.xlsx"
       fTodayName$ = "D:\냉매압축기\냉매이벤트보고서\"+TimeStr(44)+".xlsx"
 
       ' 파일을 Open 한다.
       If (FileExists(fTodayName$) = True) Then
         Set DayRpt = ExcelApp.Workbooks.Open(fTodayName$)
       Else
         '파일이 없으면 양식으로 부터 복사하여 새로운 파일을 생성한다.
  FileCopy fFormName$ , fTodayName$
  Set DayRpt = ExcelApp.Workbooks.Open(fTodayName$)
         'Excel의 위치를 초기화
  
   End If
       Set Sheet1 = DayRpt.Worksheets(1)
 i=9
 While (GetTagVal("START_ON"))
  Set Cell = Sheet1.Range("B6")
  Cell.Value = GetTagVal("TEXT")

'****************************************************************************************************
'엑셀파일에서 내용읽기
'Notice
'1.엑셀쉬트지정규칙
' - 쉬트 이름에 관계없이 쉬트의 순서를 기준으로 읽음.
'2.엑셀파일이 이미 열려있을때
' - 저장된 상태를 열어 읽음 
'****************************************************************************************************
Sub do_excel01_reading()
 
Dim ExcelApp  As Object
Dim ExcelFile As Object
Dim Sheet1    As Object
Dim Cell      As Object
 
'message
SetTagVal "EXCEL.MESSAGE","Excel file open...!"
 
'생성:excel object
Set ExcelApp = CreateObject("Excel.Application")
 
'설정:파일경로
file_path$ = "C:\TEMP\"

 '설정:파일이름(format:YYYYMMDD)
 file_name$ = file_path$ + GetTagVal("EXCEL.FILENAME") + ".xls"
 
'점검:파일존재
If (FileExists(file_name$) = True) Then
 'excel file open
        Set ExcelFile = ExcelApp.Workbooks.Open(file_name$)
 'message
 SetTagVal "EXCEL.MESSAGE","Excel file open success."
Else
 'excel application quit
        ExcelApp.Quit
        Set ExcelApp = Empty
 'message
 SetTagVal "EXCEL.MESSAGE","There is no excel file."
 PlaySound "sound_fail"
 'exit
        Exit Sub
End If
 
'설정:엑셀쉬트지정(Rule-쉬트 이름에 관계없이 쉬트의 순서를 기준으로 읽음)
Set Sheet1 = ExcelFile.Worksheets(1)
 
'읽기:줄번호
row_no# = GetTagVal ("EXCEL.ROWNO")

 '확인:줄번호없을때 초기값지정
 If row_no# = 0 Then row_no# = 1
 
'[Section:엑셀로 부터 값을 읽고 CIMON의 태그에 값쓰기]
'읽기:엑셀로 부터 셀의 값
Set Cell = Sheet1.Range("A" + CStr(row_no#))

 '태그값쓰기:읽은 엑셀의 셀값
 SetTagVal "EXCEL.D0001", Cell
cell_no$ = "B" + CStr(row_no#) : Set Cell = Sheet1.Range(cell_no$) : SetTagVal "EXCEL.D0002", Cell
cell_no$ = "C" + CStr(row_no#) : Set Cell = Sheet1.Range(cell_no$) : SetTagVal "EXCEL.D0003", Cell
cell_no$ = "D" + CStr(row_no#) : Set Cell = Sheet1.Range(cell_no$) : SetTagVal "EXCEL.D0004", Cell
 
'종료:엑셀
ExcelApp.Quit
 
'삭제:메모리
Set ExcelApp = Empty
 
'message
SetTagVal "EXCEL.MESSAGE", file_name$ + ". Excel file reading success."
PlaySound "sound_success"
 
End Sub

공유

facebooktwitterpinterestbandkakao story
퍼머링크

댓글 0

권한이 없습니다.