[英]Is it possible to open a .htm file in Excel using vbscript?
是否可以在 vbscript 中執行以下操作?
Set xlApp = CreateObject("Excel.Application")
set xlBook = xlApp.WorkBooks.Open("filename.htm")
我查看了 WorkBooks.Open 的 api,但看不到對文件名 arg 的任何限制。 它必須是 .xls 或 .xlsx 文件嗎?
(由於地震,我今天無法上班,所以我無法真正從我所在的地方進行嘗試,但如果可能的話,最好提前知道。)
兩個答案...簡短的回答是的,你可以...長的回答,你可以,但不會在 excel 中顯示 html 文件,而是在 Internet Explorer 中。
邏輯: 1 - 在 excel 上,創建一個按鈕來執行 VBA... 2 - 創建對象為 IE... set objIE = CreateObjcet("InternetExplorer.Application") 2.1 - 導航到 objIE.Navigate "filename.htm" 2.2 - 把它設為可見 objIE.Visible true ...
這是一個例子:
Function openIE(webPage)
Set openIE = CreateObject("InternetExplorer.Application")
With openIE
If not .StatusBar then .StatusBar = True
If not .Visible then .Visible = True
If not .LocationURL = webPage then .Navigate webPage
If not .FullScreen then .FullScreen = True
End With
' Do Until is here because, the script is more faster then object.
' So, we need to make this script "talk" to the Internet Explorer.
Do Until openIE.ReadyState = 4
WScript.Sleep 250
Loop
End Function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.