2016-07-16 15 views
0

私はこれらのコードを使用しています。私はこれらのファイルを保存しました(Book.html)。送信ボタンをクリックすると、データがExcelシートに入力されません

私はInternet Explorerを開いているときにフォームに記入しますが、フォームデータはExcelシートには入っていません。どの項目をHTMLのWebページに埋めますか。自動的に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エッジモードではサポートされていません。https://msdn.microsoft.com/en-us/library/dn384057 – Slai

+0

インターネットエクスプロア11のバージョン –

答えて

0

VBScriptは中括弧{}を使用しません。 CreateObjectにスペースがあります( "Excel。Application")。 <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

を使用しています。 –

+0

Sirも動作していません。オープンしていません。 –

+0

<入力ID = "サンプル" onclick = "サンプル();" Sample()の名前を変更して入力要素を識別しています。 –