excel能创建html吗,如何通过Excel电子表格使用循环创建单独的HTML发布页面

这应该是相当简单的放在循环内。

这里是一个例子。我假设文件名将来自子范围的第一行/第二列,您可以轻松修改此内容,或者询问我如何修改。我还假设Div ID(“FileName_100067”)是不变的。再次,如果需要,可以很容易地修改。

Sub HTMLinLoop()

Dim wb As Workbook: Set wb = ActiveWorkbook

Dim ws As Worksheet: Set ws = ActiveSheet

Dim rng As Range '## The full range including all columns'

Dim subRng As Range '## a variable to contain each publishObjects range'

Dim pObj As PublishObject '## A variable to contain each publishObject as we create it.'

Dim p As Long '## use this integer to iterate over the columns in rng'

Dim fileName As String '## represents just the file name to export'

Dim fullFileName As String '## the full file path for each export'

Dim divName As String '## variable for the DivID argument, assume static for now'

Set rng = ws.Range("A3:W30") '## modify as needed'

For p = 1 To rng.Columns.Count

'Identify the sub-range to use for this HTML export:'

' this will create ranges like "A:B", then "A:C", then "A:D", etc.'

Set subRng = Range(rng.Columns(1).Address, rng.Columns(p + 1).Address)

'Create the filename:'

'## modify as needed, probably using a range offset.'

fileName = subRng.Cells(1, 2).Value & "_VSE.htm"

'Concatenate the filename & path:'

'## modify as needed.'

exportFileName = "C:\Users\" & Environ("Username") & "\Desktop\" & fileName

'Create hte DIV ID:'

divName = "FileName_10067" '## modify as needed, probably using a range offset.'

'## Now, create the publish object with the above arguments:'

Set pObj = wb.PublishObjects.Add(_

SourceType:=xlSourceRange, _

fileName:=exportFileName, _

Sheet:=ws.Name, _

Source:=subRng.Address, _

HtmlType:=xlHtmlStatic, _

DivID:=divName, _

Title:="")

'## Finally, publish it!'

pObj.Publish

'## Hide the last column:'

rng.Columns(p+1).EntireColumn.Hidden = True

Next

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值