将特定范围导出为HTML [英] Export specific range into an HTML
问题描述
我试图将(A1:C10)从表单 Sheet1
导出为 HTML ,将其保存在与当前工作簿相同的目录中。我也想保留源格式。
我正在使用以下代码,但是我收到错误,我无法将目标文件夹定义为当前工作簿中的相同文件夹
Sub Export()
/ pre>
Dim rng As Range
Set rng = Sheets (Sheet1)。范围(A1:C10)
ActiveWorkbook.PublishObjects.Add(_
SourceType:= xlSourceRange,_
文件名:= file1,_
表:=Sheet1,_
来源:= rng,_
HtmlType:= xlHtmlStatic)。发布
End Sub
我也尝试过:
Sub Export()
Dim rng As Range
设置rng =表(sheet1)。范围(A1:C10)
ActiveWorkbook.PublishObjects.Add(_
SourceType:= xlSourceRange,_
fileName = =C:\exported.xlsx,_
表:=Sheet1,_
来源:= rng,_
HtmlType:= xlHtmlStatic)。发布
End Sub
解决方案
资料来源:=
期望一个地址范围的字符串值,而不是范围
对象。
包含宏的工作簿的路径可以通过
ThisWorkbook.Path
获得。Sub Export()
Dim rng As Range
file1 = ThisWorkbook.Path& \& test.html
设置rng =表(Tabelle1)。范围(A1:C10)
ActiveWorkbook.PublishObjects.Add(_
SourceType:= xlSourceRange,_
文件名:= file1,_
表:= rng.Worksheet.Name,_
来源:= rng.Address,_
HtmlType:= xlHtmlStatic )。发布
End Sub
I am trying to export the range ("A1:C10") from sheet
Sheet1
as HTML and save it in the same directory as the current workbook. I also want to keep the source formatting.I am using the following code, but I get errors and I cannot define the destination folder as the same folder where the current workbook resides.
Sub Export() Dim rng As Range Set rng = Sheets("Sheet1").Range("A1:C10") ActiveWorkbook.PublishObjects.Add( _ SourceType:=xlSourceRange, _ Filename:=file1, _ sheet:="Sheet1", _ Source:=rng, _ HtmlType:=xlHtmlStatic).Publish End Sub
I also tried this:
Sub Export() Dim rng As Range Set rng = Sheets("sheet1").Range("A1:C10") ActiveWorkbook.PublishObjects.Add( _ SourceType:=xlSourceRange, _ fileName:="C:\exported.xlsx", _ Sheet:="Sheet1", _ Source:=rng, _ HtmlType:=xlHtmlStatic).Publish End Sub
解决方案
Source:=
expects a string value with a address of a range, not aRange
object.The path of the Workbook which contains the macro can be gotten with
ThisWorkbook.Path
.Sub Export() Dim rng As Range file1 = ThisWorkbook.Path & "\" & "test.html" Set rng = Sheets("Tabelle1").Range("A1:C10") ActiveWorkbook.PublishObjects.Add( _ SourceType:=xlSourceRange, _ Filename:=file1, _ Sheet:=rng.Worksheet.Name, _ Source:=rng.Address, _ HtmlType:=xlHtmlStatic).Publish End Sub
这篇关于将特定范围导出为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!