一部のハードウェアの構成ファイルを生成する Excel ワークブックにアクセスするためのフロントとして機能する Web ページを作成しています。現在、これは概念をテストし、jscript がどのように Excel を自動化するかを理解するためのものです。
私の問題は、マクロを実行しようとすると、「予期される ';' が表示され続けることです。行 46 Char 7 でエラーが発生しました。」私の知る限り、構文は正しく、別の Excel ワークブック マクロで動作します。PC の .dll を修正し、IE の設定を確認しましたが、混乱しているのは、これが機能しないのに、他の jscript が問題なく動作する理由です。
正常に動作します: oXL.Run("ButtonTest.xlsm!Module1.buttonclick");
エラー: oXL.Run("test.xlsm!Module1.makeconfigs");
私の概念テストの完全なコード:
<!DOCTYPE html>
<html lang="en">
<body>
<SCRIPT LANGUAGE="VBScript">
</SCRIPT>
<SCRIPT LANGUAGE="JScript">
function AutomateExcel(store,direct,MdfFloor,MdfSW,Include)
{
// Start Excel and get Application object.
var oXL = new ActiveXObject("Excel.Application");
var filename = "D:\\Profiles\\ngwx36\\Desktop\\test.xlsm";
oXL.Visible = true;
// Open Staging Workbook
var oWB = oXL.Workbooks.Add(filename);
// Place vars from input in correct cell
oWB.Sheets("Instructions").Cells(1, 5).Value = store;
oWB.Sheets("Instructions").Cells(2,5).Value = direct;
oWB.Sheets("SWInventory").Cells(3,2).Value = MdfFloor;
oWB.Sheets("SWInventory").Cells(3,6).Value = MdfSW;
//checks to see if 3rd MDF needs to be included
if (Include == "Yes"){
oWB.Sheets("SWInventory").Cells(5,2).Value = "Included";
}
//fill 2 IDFs in to test atm
oWB.Sheets("SWInventory").Cells(7,2).Value = "1";
oWB.Sheets("SWInventory").Cells(7,3).Value = "1";
oWB.Sheets("SWInventory").Cells(7,4).Value = "SW01";
oWB.Sheets("SWInventory").Cells(7,6).Value = "EX2200C";
oWB.Sheets("SWInventory").Cells(8,2).Value = "2";
oWB.Sheets("SWInventory").Cells(8,3).Value = "2";
oWB.Sheets("SWInventory").Cells(8,4).Value = "SW02";
oWB.Sheets("SWInventory").Cells(8,6).Value = "EX2200C";
window.alert("Filled Sheet Just Fine");
//run config macro
oXL.Run("test.xlsm!Module1.makeconfigs");
window.alert("Process Complete");
}
</SCRIPT>
<Form Name=Input>
<p>
<label>Store Name</label>
<input type = "text"
name= "StoreName"
value = "" />
</p>
<p>
<label>File Directory</label>
<input type = "text"
name= "FilePath"
value = "" />
</p>
<p>
<label>MDF Floor #</label>
<input type = "text"
name= "MdfFloor"
value = "" />
</p>
<p>
<label>MDF Type</label>
<input type = "text"
name= "MdfType"
value = "Enter MDF SW TYpe" />
</p>
<p>
<label>MDF Include</label>
<input type = "text"
name= "MdfInc"
value = "3rd MDF Yes or No?" />
</p>
</form>
<P><INPUT id=button1 type=button value="Start Excel"
onclick="AutomateExcel Input.StoreName.Value,Input.FilePath.Value,Input.MdfFloor.Value,Input.MdfType.value,Input.MdfInc.Value">
</P>
</body>
</html>
アップデート:
予想されるエラーが発生する理由はわかりませんが、単にマクロを実行する VBScript 関数を作成することで回避策を実装しました。何らかの理由で、VB はこの特定のマクロを実行できますが、Jscript は好まないのです。
<!DOCTYPE html>
<html lang="en">
<body>
<script language = "VBscript">
function RunMacro()
dim oXL
Set oXL = GetObject(,"Excel.Application")
oXL.Run "makeconfigs"
end function
</script>
<Script Language = "jscript">
function AutomateExcel(){
var oXL = new ActiveXObject("Excel.Application");
var filename = "D:\\Profiles\\ngwx36\\Desktop\\test.xlsm";
oXL.Visible = true;
var oWB = oXL.Workbooks.Add(filename);
RunMacro();
}
</Script>
<P><INPUT id=button1 type=button value="Start Excel"
onclick="AutomateExcel()">
</P>
</body>
</html>