通常の「インターネット」では行いません。「信頼済みサイト」でのみ ActiveX を実行可能にしてから対象ページを登録して、WEB ページのデータを Excel のブックに転送して保存します。 業務アプリケーションとして「運用ルール」がきちんと決められ、システム管理者が居られると言う前提で通常は利用されます。 ▼ 以下、前提となる設定![]()
画像では、「localhost」ですが、イントラネットですと、単純にサーバー名になります 以下ソースコード
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=10">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script language="VBScript">
Const xlMaximized = -4137
Function Creata_Excel_Book()
Dim ExcelPath : ExcelPath = "c:\temp\test.xlsx"
' 処理前の確認
alert("OK")
console.log( "OK" )
' オブジェクト
Dim MyExcel
' オブジェクト作成
Set MyExcel = new CExcel
' 空の Book 作成 / 引数にパスが指定されているので、
' そのパスで上書き保存する
Set Workbook = MyExcel.Create( ExcelPath )
' セルにデータをセット
Workbook.ActiveSheet.Cells(2, 1) = "IE11+Excelです"
' 変更内容を上書き
Workbook.Save
' オブジェクト情報の表示
console.dir( MyExcel )
console.dir( Workbook )
' Excel オブジェクトの終了
MyExcel.Quit
' Windows アプリケーションとして開く
MyExcel.Load( ExcelPath )
' 解放
Set MyExcel = Nothing
End Function
Class CExcel
Public App
Public WshShell
Public ErrDescription
Private WorkBook
Public CurBook
' ************************************************
' インスタンスが作成されたときの処理
' ************************************************
Private Sub Class_Initialize()
Call InitSetting()
console.log( "Class_Initialize" )
End Sub
' ************************************************
' インスタンスが終了したときの処理
' ( Set インタンス変数 = Nothing で発生 )
' ************************************************
Private Sub Class_Terminate()
Call Quit()
console.log( "Class_Terminate" )
End Sub
' ************************************************
' 初期処理
' ************************************************
Public Default Function InitSetting()
if IsEmpty( App ) then
Set App = CreateObject("Excel.Application")
end if
if IsEmpty( WshShell ) then
Set WshShell = CreateObject("WScript.Shell")
end if
' ユーザーに入力を促すメッセージを表示させないようにする
App.DisplayAlerts = False
Set CurBook = Nothing
end function
' ************************************************
' 終了
' ************************************************
Public Function Quit()
If not IsEmpty( App ) Then
For Each Workbook In App.Workbooks
' 全てのブックを保存した事にする
WorkBook.Saved = True
Next
App.Quit
Set App = Nothing
App = Empty
Set CurBook = Nothing
End If
End Function
' ************************************************
' 表示・非表示
' ************************************************
Public Property Let Visible( bFlg )
App.Visible = bFlg
End Property
Public Property Get Visible
Visible = App.Visible
End Property
' ************************************************
' 開く
' ************************************************
Public Function Open( strPath )
on error resume next
Set Open = App.Workbooks.Open(strPath)
if Err.Number <> 0 then
Set Open = Nothing
ErrDescription = Err.Description
Exit Function
end if
on error goto 0
Set CurBook = Open
' アクティブなウィンドウを最大化
App.ActiveWindow.WindowState = xlMaximized
End Function
' ************************************************
' 新規ブック作成
' ************************************************
Public Function Create( strPath )
Dim nBooks
App.Workbooks.Add
nBooks = App.Workbooks.Count
' 戻り値セット
Set Create = App.Workbooks( nBooks )
' 処理
Set CurBook = Create
CurBook.Activate
' アクティブなウィンドウを最大化
App.ActiveWindow.WindowState = xlMaximized
if strPath <> "" then
on error resume next
CurBook.SaveAs( strPath )
if Err.Number <> 0 then
MsgBox( Err.Description )
Exit Function
end if
on error goto 0
end if
End Function
' ************************************************
' 閉じる
' ************************************************
Public Function Close( MyBook )
if IsObject( MyBook ) then
MyBook.Saved = True
MyBook.Close
Set MyBook = Nothing
MyBook = Empty
else
if CurBook is Nothing then
else
CurBook.Saved = True
CurBook.Close
Set CurBook = Nothing
end if
end if
End Function
' ******************************************************
' 上書き保存
' ******************************************************
Function Save( MyBook )
if IsObject( MyBook ) then
MyBook.Save
else
CurBook.Save
end if
End Function
' ******************************************************
' 名前を付けて保存
' ******************************************************
Function SaveAs( MyBook, strPath )
if IsObject( MyBook ) then
MyBook.SaveAs strPath
else
CurBook.SaveAs strPath
end if
End Function
' ******************************************************
' 通常アプリケーションとして開く
' ******************************************************
Function Load( strPath )
if not IsEmpty( App ) then
MsgBox( "Excel をロードする前に、Quitを実行して下さい " )
Exit Function
end if
Call WshShell.Run( _
"RunDLL32.EXE shell32.dll,ShellExec_RunDLL " & _
strPath _
)
End Function
End Class
</script>
</head>
<body>
<input type="button" value="実行" onclick="Call Creata_Excel_Book()" language="VBScript">
</body>
</html>
|
|
【IEの最新記事】
- IE11 を アプリケーションのプラットホームとして使う為の3つの設定
- IE11 : 実行済みのページのソースをクリップボードにコピーする
- VBScript : IE11のソースエディタの変更
- IE 専用 : 「信頼済みサイト」でのみ行う、WEBページのデータの Excel への転送
- VBScript のコードを書いた HTML を IEのツールメニューにアドオンする
- IE11 から VBScript で ODBCで使用されるデータベース(例えばSQLServer) より Excel でデータをエクスポートする
- IE11 で『安全だとマークされていないActiveX』を使用可能にして実行可能な Windows 処理のサンプル
- IE11 で VBScript を使う場合の注意事項 ( 古い社内アプリ移行時必見 )
- IE11 でドキュメントモードを変更して IE8 として VBscript から jQuery にアクセスする
- IEによる JavaScriptのセキュリティ上の制限とその解除
- IEの設定 : 信頼済みサイトに移動する時にダイアログを表示しないようにする
- IE8 までは、ブロック要素でなくても『page-break-after』は動作してました。というか、正式ドキュメントにそう書いてあります。
- IE11 : 画像のフルスクリーン API
- Windows7 用の IE11 がリリースされて、めでたく『WebGL』が使えるようになりました。
- HTTP ヘッダや META 要素に指定する、X-UA-Compatible による IEのドキュメントモードの変更
- IE 専用 : 「信頼済みサイト」でのみ行う、InternetExplorer.Application オブジェクト
- IE9 では動かない WEBアプリケーションの為に、IE8 のドキュメントモードで強制的に動かす為の META 記述
- IEのセキュリティゾーン関連のレジストリエントリ


画像では、「localhost」ですが、イントラネットですと、単純にサーバー名になります
以下ソースコード




