ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ByVal a As Range~¦¹Ãþ»yªkªº¥Îªk¡A¤£¤Ó²M·¡

«Øij½Ð±NÀɮפW¶Ç,§â±zªº°ÝÃD»¡²M·¡

TOP

¦^´_ 9#¡B10#

¥ýÁÂÁ¤j¤j­Ì¡A¸É»ô¤W­z©Ò»Ý¤§¸ê®Æ~¦p¤U©Ò¥Ü¡G

Sub CreateFile_Click()
'"«ØÀÉ"¥\¯à
Dim I, J As Long
'
  
  UserForm1.Hide
'»{ÃÒ
Call admit(adm)
    If adm = 2 Then
         MsgBox "±zªº¥¨¶°©|¥¼§ó·s¡A½Ð¥hO¼Ñ±N¥¨¶°§ó·s"
         Exit Sub
    End If
'--------------
  
  YS = YS_Y & " ¦~ " & YS_S
  WestYS1 = CLng(1910 + CLng(YS_Y))
  WestYS2 = CLng(1912 + CLng(YS_Y))
  
'
  Filename = UCase(FacNo.Text) & "_" & GetSsn(YS)
   If CLng(YS_Y) > 95 Then '¥[¤J96¦~·sªí³æ
    lsExcelModel = lsExcelFilePath & "96¦~¸Õºâªí.xls"
   Else
    lsExcelModel = lsExcelFilePath & "¸Õºâªí.xls"
   End If
  Workbooks.Open Filename:=lsExcelModel
  Sheets.Add After:=Worksheets(Worksheets.Count)
  Sheets(ActiveCell.Worksheet.Name).Select
  Sheets(ActiveCell.Worksheet.Name).Name = "¶×¤J"
      Columns("A:AZ").Select
      Selection.NumberFormatLocal = "@"
  ActiveWorkbook.SaveAs Filename:=lsExcelFilePath & "«ØÀɸê®Æ\" & Filename & ".xls" '¦sÀɸô®|
'----------------------------------------------------¨ú¥X¸ê®Æ
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "P_Factory" & "#" '¤u¼t°ò¥»¸ê®Æ
  SQLStr = "SELECT P_Factory.* FROM P_Factory WHERE (((P_Factory.ºÞ¨î½s¸¹)='" & FacNo & "'))"
  Call GetDataFromDB(lsDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")


If CLng(YS_Y) <= 95 Then '95¦~«e¶×¤JÀÉ®×¥\¯à
'
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "P_Exp" & "#" '¥Ó³ø®Ñµn¸ü¸ê®Æ
  SQLStr = "SELECT P_Exp.* FROM P_Exp RIGHT JOIN P_Factory ON P_Exp.R_P_FTsn = P_Factory.P_FTsn "
  SQLStr = SQLStr & "WHERE (((P_Factory.ºÞ¨î½s¸¹)='" & FacNo & "') AND ((P_Exp.¦~«×©u§O)='" & GetSsn(YS) & "')) ORDER BY P_Exp.R_P_FTsn, P_Exp.¦~«×©u§O, P_Exp.¸É¥ó"
  Call GetDataFromDB(lsDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")
'
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "P_Exp_Pipe_0" & "#" '¥Ó³ø¸ê®Æ,P_Exp_Pipe_0
  SQLStr = "SELECT P_Exp_Pipe_0.* "
  SQLStr = SQLStr & "FROM P_Factory LEFT JOIN (P_Exp LEFT JOIN P_Exp_Pipe_0 ON P_Exp.PESn = P_Exp_Pipe_0.R_PEsn) ON P_Factory.P_FTsn = P_Exp.R_P_FTsn "
  SQLStr = SQLStr & "WHERE (((P_Factory.ºÞ¨î½s¸¹)='" & FacNo & "') AND ((P_Exp.¦~«×©u§O)='" & GetSsn(YS) & "') AND ((P_Exp_Pipe_0.R_PEsn) Is Not Null)) "
  SQLStr = SQLStr & "ORDER BY P_Exp_Pipe_0.·Ï¹D½s¸¹, P_Exp_Pipe_0.¦Ã¬V·½½s¸¹, P_Exp_Pipe_0.¤ë¥÷"
  Call GetDataFromDB(lsDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")
'
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "P_Exp_Pipe_1" & "#" 'ªì¼f¸ê®Æ
  SQLStr = "SELECT P_Exp_Pipe_1.* "
  SQLStr = SQLStr & "FROM P_Factory LEFT JOIN (P_Exp LEFT JOIN P_Exp_Pipe_1 ON P_Exp.PESn = P_Exp_Pipe_1.R_PEsn) ON P_Factory.P_FTsn = P_Exp.R_P_FTsn "
  SQLStr = SQLStr & "WHERE (((P_Factory.ºÞ¨î½s¸¹)='" & FacNo & "') AND ((P_Exp.¦~«×©u§O)='" & GetSsn(YS) & "') AND ((P_Exp_Pipe_1.R_PEsn) Is Not Null)) "
  SQLStr = SQLStr & "ORDER BY P_Exp_Pipe_1.·Ï¹D½s¸¹, P_Exp_Pipe_1.¦Ã¬V·½½s¸¹, P_Exp_Pipe_1.¤ë¥÷"
  Call GetDataFromDB(lsDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")
'
Else '96¦~¶×¤JÀÉ®×
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "applyusersend" & "#" '¥Ó³ø®Ñµn¸ü¸ê®Æ
  SQLStr = "SELECT applyusersend.* FROM applyusersend "
  SQLStr = SQLStr & "WHERE (((applyusersend.ºÞ¨î½s¸¹)='" & FacNo & "') AND ((applyusersend.¦~«×©u§O)='" & GetSsn(YS) & "'))"
  Call GetDataFromDB(lsDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")

  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "chimneyapply" & "#" '¥Ó³ø¸ê®Æ
  SQLStr = "SELECT chimneyapply.* FROM chimneyapply "
  SQLStr = SQLStr & "WHERE (((chimneyapply.ºÞ¨î½s¸¹)='" & FacNo & "') AND ((chimneyapply.¦~«×©u§O)='" & GetSsn(YS) & "'))"
  SQLStr = SQLStr & "ORDER BY chimneyapply.·Ï¹D½s¸¹, chimneyapply.¦Ã¬V·½½s¸¹, chimneyapply.¤ë¥÷"
  Call GetDataFromDB(lsDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")

End If

'kuo add start 94/5/24
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "X_ExpRep" & "#" '
  SQLStr = "SELECT DISTINCT X_ExpRep.* "
  SQLStr = SQLStr & "FROM X_ExpRep LEFT JOIN X_ExpRepPol ON (X_ExpRep.XERPFTFacNo = X_ExpRepPol.XRPPFTFacNo) AND (X_ExpRep.XERMEREquipNo = X_ExpRepPol.XRPMEREquipNoP) AND (X_ExpRep.XERSDate = X_ExpRepPol.XRPSDate) AND (X_ExpRep.XEROrder = X_ExpRepPol.XRPOrder) AND (X_ExpRep.XERPosition = X_ExpRepPol.XRPPosition) AND (X_ExpRep.XERFlag = X_ExpRepPol.XRPFlag) "
  SQLStr = SQLStr & "WHERE (((X_ExpRepPol.XRPCPOName)='²¸®ñ¤Æª«' Or (X_ExpRepPol.XRPCPOName)='´á®ñ¤Æª«') AND ((X_ExpRep.XERPFTFacNo)='" & FacNo & "') AND ((Year([XERSDate])) >=" & WestYS1 & ") AND ((Year([XERSDate])) <=" & WestYS2 & "))"
  Call GetDataFromDB(lsExpDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")
'
  -«ÝÄò

TOP

EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "X_ExpRepPol" & "#" '
  SQLStr = "SELECT X_ExpRepPol.* FROM X_ExpRepPol "
  SQLStr = SQLStr & "WHERE (((X_ExpRepPol.XRPPFTFacNo)='" & FacNo & "') AND ((X_ExpRepPol.XRPCPOName)='²¸®ñ¤Æª«') AND ((Year([XRPSDate]))>=" & WestYS1 & ")) OR (((X_ExpRepPol.XRPPFTFacNo)='" & FacNo & "') AND ((X_ExpRepPol.XRPCPOName)='´á®ñ¤Æª«') AND ((Year([XRPSDate]))>=" & WestYS1 & "))"
  Call GetDataFromDB(lsExpDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")
'
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "X_ExpCtl" & "#" '
  SQLStr = "SELECT X_ExpCtl.* FROM X_ExpCtl WHERE (((X_ExpCtl.XECPFTFacNo)='" & FacNo & "') AND ((Year([XECSDate]))>=" & WestYS1 & "))"
  Call GetDataFromDB(lsExpDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")
'
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "X_ExpCtlPol" & "#" '
  SQLStr = "SELECT X_ExpCtlPol.* FROM X_ExpCtlPol WHERE (((X_ExpCtlPol.XCPPFTFacNo)='" & FacNo & "') AND ((X_ExpCtlPol.XCPCPOName)='²¸®ñ¤Æª«') AND ((Year([XCPSDate]))>=" & WestYS1 & ")) OR (((X_ExpCtlPol.XCPPFTFacNo)='" & FacNo & "') AND ((X_ExpCtlPol.XCPCPOName)='´á®ñ¤Æª«') AND ((Year([XCPSDate]))>=" & WestYS1 & "))"
  Call GetDataFromDB(lsExpDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")
'
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "X_ExpRepReq" & "#" '
  SQLStr = "SELECT X_ExpRepReq.* "
  SQLStr = SQLStr & "FROM X_ExpRep LEFT JOIN X_ExpRepReq ON (X_ExpRep.XERMEREquipNo = X_ExpRepReq.XRRMEREquipNoP) AND (X_ExpRep.XERFlag = X_ExpRepReq.XRRFlag) AND (X_ExpRep.XERPosition = X_ExpRepReq.XRRPosition) AND (X_ExpRep.XEROrder = X_ExpRepReq.XRROrder) AND (X_ExpRep.XERSDate = X_ExpRepReq.XRRSDate) AND (X_ExpRep.XERPFTFacNo = X_ExpRepReq.XRRPFTFacNo) "
  SQLStr = SQLStr & "WHERE (((X_ExpRepReq.XRRSn) Is Not Null) AND ((Year([XERSDate]))>=" & WestYS1 & ") AND ((X_ExpRep.XERPFTFacNo)='" & FacNo & "') AND ((X_ExpRepReq.XRRKind)<3)) "
  SQLStr = SQLStr & "ORDER BY X_ExpRep.XERMEREquipNo, X_ExpRep.XERSDate, X_ExpRep.XEROrder, X_ExpRepReq.XRRSn"
  Call GetDataFromDB(lsExpDBFilePathName, SQLStr, EmptyRowIndex + 1, "Yes")
'
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "X_ExpRepAgt" & "#" '
  SQLStr = "SELECT X_ExpRepAgt.* "
  SQLStr = SQLStr & "FROM X_ExpRep LEFT JOIN X_ExpRepAgt ON (X_ExpRep.XERFlag = X_ExpRepAgt.XRAFlag) AND (X_ExpRep.XERPosition = X_ExpRepAgt.XRAPosition) AND (X_ExpRep.XEROrder = X_ExpRepAgt.XRAOrder) AND (X_ExpRep.XERSDate = X_ExpRepAgt.XRASDate) AND (X_ExpRep.XERMEREquipNo = X_ExpRepAgt.XRAMEREquipNoP) AND (X_ExpRep.XERPFTFacNo = X_ExpRepAgt.XRAPFTFacNo) "
  SQLStr = SQLStr & "WHERE (((X_ExpRepAgt.XRASn) Is Not Null) AND ((X_ExpRep.XERPFTFacNo)='" & FacNo & "') AND (Year([XERSDate])>2002)) "
  SQLStr = SQLStr & "ORDER BY  X_ExpRepAgt.XRASn"
  Call GetDataFromDB(lsExpDBFilePathName, SQLStr, EmptyRowIndex + 1, "No")


'
  EmptyRowIndex = GetEmptyRowIndex("¶×¤J")
  Cells(EmptyRowIndex, 3).Value = "#" & "End" & "#"
'----------------------------------------------------¨D¨úP_FactoryStartRowNbr,P_FactoryCount,P_FactoryFieldCount
Call GetIndex("¶×¤J", "P_Factory")
If CLng(YS_Y) <= 95 Then '95¦~¶×¤J¥\¯à
Call GetIndex("¶×¤J", "P_Exp")
Call GetIndex("¶×¤J", "P_Exp_Pipe_0")
Call GetIndex("¶×¤J", "P_Exp_Pipe_1")
Else
Call GetIndex("¶×¤J", "applyusersend")
Call GetIndex("¶×¤J", "chimneyapply")
End If

Call GetIndex("¶×¤J", "X_ExpRep")
Call GetIndex("¶×¤J", "X_ExpRepPol")
Call GetIndex("¶×¤J", "X_ExpCtl")
Call GetIndex("¶×¤J", "X_ExpCtlPol")
Call GetIndex("¶×¤J", "X_ExpRepReq")
Call GetIndex("¶×¤J", "X_ExpRepAgt")
Call GetIndex("¶×¤J", "End")
'
If P_FactoryCount = 0 Then
MsgBox "¦bP_Factory¤¤,§ä¤£¨ì¸ê®Æ,µLªkÄ~Äò°õ¦æ"
Exit Sub
End If
If P_FactoryCount > 1 Then
MsgBox "¦bP_Factory¤¤,¸ê®Æ¤j©ó1µ§,µLªkÄ~Äò°õ¦æ"
Exit Sub
End If
'°t¦X961©u­×¥¿
'If P_ExpCount = 0 Then
'MsgBox "¦bP_Exp¤¤,§ä¤£¨ì¸ê®Æ,µLªkÄ~Äò°õ¦æ"
'Exit Sub
'End If
'If P_Exp_Pipe_0Count = 0 Then
'MsgBox "¦b¥Ó³ø¤¤,§ä¤£¨ì¸ê®Æ,µLªkÄ~Äò°õ¦æ"
'Exit Sub
'End If
'§ï¦¨µLªì¼f¸ê®Æ¤]¥i¼f¬d
'If P_Exp_Pipe_1Count = 0 Then
'MsgBox "¦bªì¼f¤¤,§ä¤£¨ì¸ê®Æ,µLªkÄ~Äò°õ¦æ"
'Exit Sub
'End If
'----------------------------------------------------¶ñ¤J¸ê®Æ
  Call Filldata
'----------------------------------------------------
'
ActiveWorkbook.Save '¦sÀÉ
End Sub
-----------------------------------------------------------------------§Ú¬O¤À¹j½u--------

«ô°U¦U¦ì¤j¤j¡A¨D¸Ñ¬°¦ó§Ú¿é¤J¬O99¦~®É¡A¦sÀɪº«¬ºA¬OÀɦW_099X¡A¨ä¤¤X¬O¤À¬°4©u¡A¦ý·í§Ú¬O¿é¤J100¦~®É¡A¦sÀÉ«o¬OÀɦW_010¡AµLªkÅã¥Ü©u§O¡C
YS = YS_Y & " ¦~ " & YS_S   
YS_Y ¬°¦~«×©u§O¡BYS_S ¬°©u§O

¥ýÁÂÁ¦U¦ì!! ÁÂÁ¤j®a

TOP

¦^´_ 13# sayloveme
¦ý·í§Ú¬O¿é¤J100¦~®É¡A¦sÀÉ«o¬OÀɦW_010¡AµLªkÅã¥Ü©u§O¡C
ÅܼƤ£­n³]»PÃöÁä¦r¬Û¦P
ActiveWorkbook.SaveAs Filename:=lsExcelFilePath & "«ØÀɸê®Æ\" & Filename & ".xls" '¦sÀɸô®|
¦sÀÉÀɦW ->  Filename = UCase(FacNo.Text) & "_" & GetSsn(YS)  ->   FacNo.Text   ,  GetSsn(YS)  ¥¦ªº(¦r¦ê,­È) ¤£ª¾¹D
§A¤W¶Ç¤F¤@°ïµ{¦¡½X ÁÙ¬O¤ù¬q  11# ¤£¬O«Øij½Ð±NÀɮפW¶Ç,§â±zªº°ÝÃD»¡²M·¡

TOP

¬Ý¨ì±z¶K¤W¨Óªºµ{¦¡½X,§@ªÌÀ³¬O¹ïµ{¦¡»y¨¥¨ã¦³¬Û·íªº¥\¤O,
¬ã§P±z¬O·Q©µ¥Î¦¹¤@ÀÉ®×»Pµ{§Ç,«Øij±zª½±µ»P§@ªÌ³sô,¥H¸Ñ¨M±zªº°ÝÃD
©Î¬O±N¾ã­ÓexcelÀɮפW¶Ç´M¨D¸Ñµª

TOP

¦^´_ 14#¡B15#

¥ýÁÂÁ¨â¦ì¤j¤jªº¸ÑÄÀ¡Aªº½T¦¹ª©¥»¬O¸g¥Ñ¥»¤½¥q¤H­û¼g¥X¡A¦ý¥Ñ©óÁ`¤½¥q¤H­û¦b¥x¥_¡A¦Ó§Ú­Ì¥Ø«e¦b°ª¶¯¡A¥[¤W¦¹ª©¦­¦b¥Á°ê90¦~¥ª¥k´N¦³¤F¡A
¥[¤W«e«á¤£¤Ö¤H­û§ó·s¹Lª©¥»¥B¦~¥N¤[»·¡A§Ú¤]µLªk¤F¸Ñ³o·í¤¤¬Y¨Ç¦r¦ê¬O§_»P·í®ÉÀɮצ³¬ÛÃö³sµ²¡A¤H­ûªºÅÜ°Ê¥[¤WÀɮפ[»·¡A¥[¤W§Ú¨Ã«D±M·~¥»¬ì¥X¨­¡A
¥i¯à³y¦¨¦U¦ì³Â·Ð¡A¦b¦¹¦V¤j®a»¡Án©êºp¡C

Àɮפ譱¡A§Ú¤]¤£¤è«K¤W¶Ç¡A¤£ºÞ¦p¦ó¡A§Ú±q¤¤Àò¨ú¤£¤Öª¾ÃÑ¡A¥ýÁÂÁ¤j®a¡CÁÂÁÂ!!

TOP

        ÀR«ä¦Û¦b : ®É®É¦n¤ß´N¬O®É®É¦n¤é¡C
ªð¦^¦Cªí ¤W¤@¥DÃD