2016-07-16 2 views
0

나는이 코드를 사용하고 있습니다. 이 파일을 저장했습니다 (Book.html).제출 버튼을 클릭하면 데이터가 엑셀 시트에 들어오지 않습니다

Internet Explorer를 열면 양식을 채우지 만 양식 데이터가 Excel 시트에 들어오지 않습니다. 어떤 항목을 HTML 웹 페이지에 채 웁니다. 자동으로 Excel 시트가 나타납니다.

<!DOCTYPE html> 
<html> 
    <head> 
     <title></title> 
    </head> 
    <body> 
     <script language="vbscript" type="text/vbscript"> 
     Sub Sample(){ 
      Dim iRow 
      Set objExcel = CreateObject("Excel. Application") 
      Set objWorkbook = objExcel.Workbooks.Open("C:\Users\VAIBHAV BEDI\Desktop\Book1.xlsx") 
      Set objWorksheet = objWorkbook.Worksheets("Book1") 
      objExcel.Visible = True 
      Set XlSheet = objWorkbook.Sheets(1) 
      XlSheet.Activate 
      iRow = 1 

      With objExcel 

       Do While .Cells(iRow, 1).Value <> "" 
        .Cells(iRow, 1).Activate 
        iRow = iRow + 1 
       Loop 

       .Cells(iRow, 1).Value = Document.GetElementsByName("fname")(0).Value 
       .Cells(iRow, 2).Value = Document.GetElementsByName("lname")(0).Value 
       .Cells(iRow, 3).Value = Document.GetElementsByName("Add1")(0).Value 
       .Cells(iRow, 4).Value = Document.GetElementsByName("Add2")(0).Value 

       MsgBox "Data Added Successfully”, vbinformation" 

       Document.GetElementsByName("fname")(0).Value = "" 
       Document.GetElementsByName("lname")(0).Value = "" 
       Document.GetElementsByName("Add1")(0).Value = "" 
       Document.GetElementsByName("Add2")(0).Value = "" 

      End With 

      objWorkbook.Save 
      objWorkbook.Close 
      Set objWorksheet = Nothing 
      Set objWorkbook = Nothing 
      Set objExcel = Nothing 
     End Sub 
     } 
     </script> 
     <form> 
      First name:<br> 
      <input name="fname" type="text" value=""><br> 
      Last name :<br> 
      <input name="lname" type="text" value=""><br> 
      Address1 :<br> 
      <input name="Add1" type="text" value=""><br> 
      Address2 :<br> 
      <input name="Add2" type="text" value=""><br> 
      <br> 
      <input id="Sample" onclick="Sample();" type="button" value= 
      "Submit"><br> 
      <form></form> 
     </form> 
    </body> 
</html> 
+2

안녕하십니까. 코드를 링크로 게시하는 대신 질문 자체에 관련 코드를 추가해야합니다. 이렇게하면 사람들이 질문을 이해하고 대답하기가 더 쉬워집니다. – UditS

+0

어떤 버전의 Internet Explorer입니까? VBScript는 IE11 Edge 모드에서 더 이상 지원되지 않습니다. https://msdn.microsoft.com/en-us/library/dn384057 – Slai

+0

인터넷 익스플로러 11 버전 –

답변

0

VBScript는 중괄호 {}를 사용하지 않습니다. CreateObject에 공간이 있습니다 ("Excel. 응용 프로그램"). <input id="Sample" onclick="Sample();" 이름 바꾸기 Sample() 입력 요소를 식별하는 데 사용 중입니다.

<!DOCTYPE html> 
<html> 
    <head> 
     <title></title> 
    </head> 
    <body> 
     <script language="vbscript" type="text/vbscript"> 
     Sub TestExcel() 
      Dim iRow 
      Set objExcel = CreateObject("Excel.Application") 
      Set objWorkbook = objExcel.Workbooks.Open("C:\Users\VAIBHAV BEDI\Desktop\Book1.xlsx") 
      Set objWorksheet = objWorkbook.Worksheets("Book1") 
      objExcel.Visible = True 
      Set XlSheet = objWorkbook.Sheets(1) 
      XlSheet.Activate 
      iRow = 1 

      With objExcel 

       Do While .Cells(iRow, 1).Value <> "" 
        .Cells(iRow, 1).Activate 
        iRow = iRow + 1 
       Loop 

       .Cells(iRow, 1).Value = Document.GetElementsByName("fname")(0).Value 
       .Cells(iRow, 2).Value = Document.GetElementsByName("lname")(0).Value 
       .Cells(iRow, 3).Value = Document.GetElementsByName("Add1")(0).Value 
       .Cells(iRow, 4).Value = Document.GetElementsByName("Add2")(0).Value 

       MsgBox "Data Added Successfully”, vbinformation" 

       Document.GetElementsByName("fname")(0).Value = "" 
       Document.GetElementsByName("lname")(0).Value = "" 
       Document.GetElementsByName("Add1")(0).Value = "" 
       Document.GetElementsByName("Add2")(0).Value = "" 

      End With 

      objWorkbook.Save 
      objWorkbook.Close 
      Set objWorksheet = Nothing 
      Set objWorkbook = Nothing 
      Set objExcel = Nothing 
     End Sub 

     </script> 
     <form> 
      First name:<br> 
      <input name="fname" type="text" value=""><br> 
      Last name :<br> 
      <input name="lname" type="text" value=""><br> 
      Address1 :<br> 
      <input name="Add1" type="text" value=""><br> 
      Address2 :<br> 
      <input name="Add2" type="text" value=""><br> 
      <br> 
      <input id="Sample" onclick="TestExcel();" type="button" value= 
      "Submit"><br> 
     </form> 
    </body> 
</html> 
+0

을 사용하고 있습니다. 동일한 조건. 열기 Excel 파일을 사용하고 있지 않습니다. –

+0

선생님 역시 작동하지 않습니다. 파일을 열 수 없습니다. –

+0

<입력 ID = "샘플"onclick = "샘플();" Sample()의 이름을 바꾸면 입력 요소를 식별하는 데 사용됩니다. –