如何将一系列 Excel 单元格写入并保存为单独的 HTML 文件
How to write and save a range of Excel cells as separate HTML files
解释一下,我正在 Outlook365 中创建一组专业的电子邮件签名,并试图统一创建它们,只有用户联系方式不同(自然)。
为此,我将我们的用户数据放在 table 中,我将使用 HTML 代码为每一行填充一个单元格,动态更改每一行的信息,制作一个独特的模板化每个用户的签名。
然而,我正在努力寻找的部分是一段代码,它将获取每个单元格的数据并为每个单独的单元格生成一个 HTML 文件。澄清一下:我预计 200 个单元格将生成 200 个 HTML 文档,全部来自我的 Excel sheet.
的 'HTML' 列
Name
Email address
Phone number
HTML
Joe Bloggs
jb@website.com
079998
<table style="width: ...
Billy Bloggs
bb@website.com
079999
<table style="width: ...
Phil Bloggs
pb@website.com
080000
<table style="width: ...
我查看了该站点上的其他查询,我相信 VBA 可以解决这个问题,但是我尝试过的 VBA 只接受了 a table数据 并使其成为 HTML 文件,甚至 column of cells into a single file。我真的希望有人可以帮助确定一种方法,将每个单元格简单地写入我本地驱动器上自己的 HTML 文件。
该代码适用于您启动它的 sheet。我使用名称列作为文件名。根据需要更改它。
这是将列的每个单元格保存到单个文件的方法:
Sub WriteCellHTML()
Const colToWrite As Long = 4
Const colToFileName As Long = 1
Const firstRow As Long = 2
Const path As String = "E:\Test\" 'don't forget the backslash at the end
Dim currRow As Long
currRow = firstRow
Do Until Cells(currRow, colToFileName) = ""
Close
Open path & Cells(currRow, colToFileName) & ".htm" For Output As #1
Print #1, Cells(currRow, colToWrite)
Close
currRow = currRow + 1
Loop
End Sub
解释一下,我正在 Outlook365 中创建一组专业的电子邮件签名,并试图统一创建它们,只有用户联系方式不同(自然)。
为此,我将我们的用户数据放在 table 中,我将使用 HTML 代码为每一行填充一个单元格,动态更改每一行的信息,制作一个独特的模板化每个用户的签名。
然而,我正在努力寻找的部分是一段代码,它将获取每个单元格的数据并为每个单独的单元格生成一个 HTML 文件。澄清一下:我预计 200 个单元格将生成 200 个 HTML 文档,全部来自我的 Excel sheet.
的 'HTML' 列Name | Email address | Phone number | HTML |
---|---|---|---|
Joe Bloggs | jb@website.com | 079998 | <table style="width: ... |
Billy Bloggs | bb@website.com | 079999 | <table style="width: ... |
Phil Bloggs | pb@website.com | 080000 | <table style="width: ... |
我查看了该站点上的其他查询,我相信 VBA 可以解决这个问题,但是我尝试过的 VBA 只接受了 a table数据 并使其成为 HTML 文件,甚至 column of cells into a single file。我真的希望有人可以帮助确定一种方法,将每个单元格简单地写入我本地驱动器上自己的 HTML 文件。
该代码适用于您启动它的 sheet。我使用名称列作为文件名。根据需要更改它。
这是将列的每个单元格保存到单个文件的方法:
Sub WriteCellHTML()
Const colToWrite As Long = 4
Const colToFileName As Long = 1
Const firstRow As Long = 2
Const path As String = "E:\Test\" 'don't forget the backslash at the end
Dim currRow As Long
currRow = firstRow
Do Until Cells(currRow, colToFileName) = ""
Close
Open path & Cells(currRow, colToFileName) & ".htm" For Output As #1
Print #1, Cells(currRow, colToWrite)
Close
currRow = currRow + 1
Loop
End Sub