VBA Excel将列表框结果导出为HTML
我正在尝试将列表框的结果导出到HTML文件,但仅通过导出第一列,我也希望从列表框导出结果。有人帮我吗 代码:VBA Excel将列表框结果导出为HTML,excel,vba,Excel,Vba,我正在尝试将列表框的结果导出到HTML文件,但仅通过导出第一列,我也希望从列表框导出结果。有人帮我吗 代码: Private Sub CreateHTML() 'Create an .html file in the assigned directory. Dim sFile As Variant sFile = Application.GetSaveAsFilename(fileFilter:="HTML Files (*.html), *.htm")
Private Sub CreateHTML()
'Create an .html file in the assigned directory.
Dim sFile As Variant
sFile = Application.GetSaveAsFilename(fileFilter:="HTML Files (*.html), *.htm")
'Open up the temp HTML file and format the header.
Open sFile For Output As #1
Print #1, "<html>"
Print #1, "<head>"
Print #1, "<style type=""text/css"">"
Print #1, "table {font-size: 16px;font-family: Optimum, Helvetica, sans-serif; border-collapse: collapse}"
Print #1, "tr {border-bottom: thin solid #A9A9A9;}"
Print #1, "td {padding: 4px; margin: 3px; padding-left: 20px; width: 75%; text-align: justify;}"
Print #1, "th { background-color: #A9A9A9; color: #FFF; font-weight: bold; font-size: 28px; text-align: center;}"
Print #1, "td:first-child { font-weight: bold; width: 25%;}"
Print #1, "</style>"
Print #1, "</head>"
Print #1, "<body>"
Print #1, "<table class=""table""><thead><tr class=""firstrow""><th colspan=""2"">RESULTS</th></tr></thead><tbody>"
Dim i As Long
Dim strFind As String
For i = 0 To Me.ListBox1.ListCount - 1
'EDIT HERE TO CHANGE IT TO YOUR LINKING
Print #1, "<tr><td>"
Print #1, Me.ListBox1.List(i)
Print #1, "</td><td>"
Print #1, "</td></tr>"
Next i
'Add ending HTML tags
Print #1, "</body>"
Print #1, "</html>"
Close
End Sub
Private Sub-CreateHTML()
'在分配的目录中创建一个.html文件。
作为变体的Dim-sFile
sFile=Application.GetSaveAsFilename(文件过滤器:=“HTML文件(*.HTML),*.htm”)
'打开临时HTML文件并格式化标题。
打开sFile,输出为#1
打印#1“
打印#1“
打印#1“
打印#1,“表格{字体大小:16px;字体系列:最佳,Helvetica,无衬线;边框折叠:折叠}”
打印#1,“tr{边框底部:薄实心#A9A9;}”
打印#1,“td{填充:4px;边距:3px;左填充:20px;宽度:75%;文本对齐:对齐;}”
打印#1,“th{背景色:#A9A9;颜色:#FFF;字体大小:粗体;字体大小:28px;文本对齐:居中;}”
打印#1,“td:first child{字体大小:粗体;宽度:25%;}”
打印#1“
打印#1“
打印#1“
打印#1,“结果”
我想我会坚持多久
Dim strFind As字符串
对于i=0到Me.ListBox1.ListCount-1
'在此处编辑以将其更改为您的链接
打印#1“
打印#1,Me.ListBox1.List(i)
打印#1“
打印#1“
接下来我
'添加结束HTML标记
打印#1“
打印#1“
接近
端接头
下载链接:
在excel文件中,您在循环中写入了这一行
Print #1, strFind = Me.ListBox1.List(i)
[strFind=Me.ListBox1.List(i)]的结果为false,并写入文件
但是在你的代码里你写的
Print #1, Me.ListBox1.List(i)
最后一个代码运行正常,只需在excel中更改代码
更新:
如果您需要所有列,那么
Print #1, "<tr><td>"
Print #1, Me.ListBox1.List(i,1)
Print #1, "</td><td>"
Print #1, Me.ListBox1.List(i,2)
Print #1, "</td><td>"
Print #1, Me.ListBox1.List(i,3)
Print #1, "</td><td>"
Print #1, Me.ListBox1.List(i,....)
Print #1, "</td></tr>"
打印#1“
打印#1,Me.ListBox1.List(i,1)
打印#1“
打印#1,Me.ListBox1.List(i,2)
打印#1“
打印#1,Me.ListBox1.List(i,3)
打印#1“
打印#1,Me.ListBox1.List(i,…)
打印#1“
您的代码从列表框导出结果,但您也希望从列表框导出结果吗?你说的是另一个列表框吗?请澄清你的问题。是的,但是这个代码:Print#1,Me.ListBox1.List(i)只导出第一列,我需要导出所有Listbox值。