我想你缺少的一部分是如何訪問VBScript中的Excel對象。您訪問Excel對象在VBScript中的方法是撥打以下到腳本
Set myxlObject = CreateObject("Excel.Application")
Set myxlApplication = myxlObject.Application
有了,你將能夠做幾乎任何東西,你已經在VBA VBScript中完成,但現在,然後你會需要調用該應用程序對象來訪問其他對象。例如:
Set myWorkBook = myxlApplication.Workbooks.Open("C:\Wherever\Whatever.xlsx")
有關,你可以通過這個「Excel.Application」對象訪問看到這個頁面的屬性和方法的詳細信息:Application Object (Excel)
下面的腳本將輸出的名稱和鏈接地址的在特定範圍的工作表上添加到控制檯。這種使用cscript
可能更實際使用該腳本的
Set fso = CreateObject("Scripting.FileSystemObject")
curDir = fso.GetAbsolutePathName(".")
Set myxlObject = CreateObject("Excel.Application")
Set myxlApplication = myxlObject.Application
Set myWorkBook = myxlApplication.Workbooks.Open(curDir & "\24048353.xlsx") 'Change to the actual workbook that has the Hyperlinks
Set myWorkSheet = myWorkBook.Worksheets(1)
myxlApplication.Visible = False
Set rng = myWorkSheet.Range("A2:A3") 'Change to the actual range that has the Hyperlinks
For Each row In rng.Rows
myLinkName = row.Cells(1, 1).Hyperlinks(1).Name
myLinkURL = row.Cells(1, 1).Hyperlinks(1).Address
wscript.echo myLinkName & " " & myLinkURL
Next
運行是將結果輸出到文件中這樣:
Set fso = CreateObject("Scripting.FileSystemObject")
curDir = fso.GetAbsolutePathName(".")
Set myLinksFile = fso.OpenTextFile(curDir & "\mylinks.txt", 8, True)
Set myxlObject = CreateObject("Excel.Application")
Set myxlApplication = myxlObject.Application
Set myWorkBook = myxlApplication.Workbooks.Open(curDir & "\24048353.xlsx") 'Change to the actual workbook that has the Hyperlinks
Set myWorkSheet = myWorkBook.Worksheets(1)
myxlApplication.Visible = False
Set rng = myWorkSheet.Range("A2:A3") 'Change to the actual range that has the Hyperlinks
For Each row In rng.Rows
myLinkName = row.Cells(1, 1).Hyperlinks(1).Name
myLinkURL = row.Cells(1, 1).Hyperlinks(1).Address
mylinksFile.WriteLine myLinkName & ", " & myLinkURL
Next
mylinksFile.Close
我怕我不知道的特定於VBScript的文檔(我只使用Excel中的VBA)。但是,如果我的帖子回答了您的問題或有用,請隨時接受它或給它一個upvote! :) – Zairja
我已添加有關您的超鏈接問題的其他信息。 – Zairja