将Excel作为网页发布

我尝试使用VB脚本将Excel作为网页保存。我面临的问题是excel中的表名(例如Sheet1)也被保存在网页中。我不希望表格名称出现在网页中。将Excel作为网页发布

我发现的一个解决方案是,如果excel发布为网页(而不是保存为网页),那么它将不包含工作表名称。但我在使用VB脚本尝试时面临着一些问题。以下是代码:

Dim objApp, objBook, objRange, objSheet 

Set objApp = CreateObject("Excel.Application")

objApp.Visible = False

Set objBook = objApp.Workbooks.Open("C:\Dashboard\excel_files\Account Executive.xlsx")

Set objSheet = objBook.worksheets("Account Executive")

Set objRange = objSheet.Range("C5:I30")

With objBook.PublishObjects.Add(xlSourceRange, "C:\EXCEL_TO_HTML_RANGE.htm", "Account Executive", objRange.Address, xlHtmlStatic, "Title of the page").Publish(True)

End With

objBook.Close

objApp.Quit

Set objSheet = Nothing

Set objRange = Nothing

Set objApp = Nothing

该代码给出了代码为800A03EC的未知运行时错误。 无论如何要纠正这些代码或其他方式从网页中删除工作表名称?

在此先感谢。 :)

由于@AxelRichter 与2010年Excel中的最后工作代码:

Dim objApp, objBook, objRange, objSheet 

Set objApp = CreateObject("Excel.Application")

objApp.Visible = False

Set objBook = objApp.Workbooks.Open("C:\Dashboard\excel_files\OU Dashboard.xlsx")

Set objSheet = objBook.worksheets("OU Dashboard")

Set objRange = objSheet.Range("C5:J30")

Dim oPOs, oPO

Set oPOs = objBook.PublishObjects

Set oPO = oPOs.Add(4, "C:\Dashboard\EXCEL_TO_HTML_RANGE.htm", "OU Dashboard", "$C$5:$J$30", 0, "TableDIVID", "Title of the page")

oPO.Publish (True)

set oPO = Nothing

set oPOs = Nothing

Set objSheet = Nothing

Set objRange = Nothing

objBook.Close False

set objBook = Nothing

objApp.Quit

Set objApp = Nothing

回答:

有三个问题与您的代码。

第一:常量xlSourceRangexlHtmlStatic可能是未定义的。所以请改用它们的值。有关XlSourceType和XlHTMLType,请参阅https://msdn.microsoft.com/en-us/library/office/ff823068.aspx。

第二:With需要由Add返回的对象而不是Publish的响应。

第三:您已将DivIDTitle搞混了。

Dim objApp, objBook, objRange, objSheet 

Set objApp = CreateObject("Excel.Application")

objApp.Visible = False

Set objBook = objApp.Workbooks.Open("C:\Dashboard\excel_files\Account Executive.xlsx")

Set objSheet = objBook.worksheets("Account Executive")

Set objRange = objSheet.Range("C5:I30")

With objBook.PublishObjects.Add(4, "C:\EXCEL_TO_HTML_RANGE.htm", "Account Executive", objRange.Address, 0, "TableDIVID", "Title of the page")

.Publish(True)

End With

objBook.Close False

objApp.Quit

Set objSheet = Nothing

Set objRange = Nothing

Set objApp = Nothing

With .. End With可以用下面的代码来替换用于调试:

... 

Dim oPOs, oPO

Set oPOs = objBook.PublishObjects

Set oPO = oPOs.Add(4, "C:\EXCEL_TO_HTML_RANGE.htm", "Account Executive", "$C$5:$I$30", 0, "TableDIVID", "Title of the page")

oPO.Publish (True)

...

以上是 将Excel作为网页发布 的全部内容, 来源链接: utcz.com/qa/258617.html

回到顶部