ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 2406|回复: 2

[原创] Excel生成网页文件

[复制链接]

TA的精华主题

TA的得分主题

发表于 2012-8-17 14:54 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖已被收录到知识树中,索引项:文件操作和FSO
Excel生成网页文件
Sub CommandButton1_Click()
    Call FileYN
    Call WFileTop
    n = 4
    For i = 0 To 100000
        Sheets(1).Cells(1, 1) = n    '位置变量
        '写分类标签
        If Sheets(1).Cells(n, 2) <> "" And Sheets(1).Cells(n, 3) <> "" Then
            If Sheets(1).Cells(n, 2) = "分类名" Then Call WType
            n = n + 1
            Sheets(1).Cells(1, 1) = n    '位置变量
        End If
        '写网址名
        If Sheets(1).Cells(n, 3) <> "" And Sheets(1).Cells(n, 2) = "" Then
            Call WFile
        End If
        n = Sheets(1).Cells(1, 1)    '位置变量
        If Sheets(1).Cells(n, 3) = "" And Sheets(1).Cells(n, 2) = "" Then GoTo 10
    Next
10  Call WFilefoot
    MsgBox "ok"
    Sheets(1).Cells(1, 1) = ""
End Sub
Sub WType()    '写入网址分类,单独一行
    Dim fso, MyFile
    Filename = ThisWorkbook.Path & "\" & "index.html"
    n = Sheets(1).Cells(1, 1)
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set MyFile = fso.OpenTextFile(Filename, 8)
    MyFile.Writeline ("  <TR align=left bgColor=#ffffff>")
    MyFile.Writeline ("     <TD class=tbl_head colSpan=4 height=18><A><IMG height=6 src=""网址导航.files/dot3.gif"" width=3>&nbsp;<SPAN  class=f_l>")
    MyFile.Writeline Sheets(1).Cells(n, 3)
    MyFile.Writeline (" </SPAN></A></TD></TR>")
    MyFile.Close
    Set fso = Nothing
    Set MyFile = Nothing
End Sub
Private Sub WFile()    '写入网址连接一行4个
    Dim fso, MyFile
    Filename = ThisWorkbook.Path & "\" & "index.html"
    n = Sheets(1).Cells(1, 1)    '位置变量
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set MyFile = fso.OpenTextFile(Filename, 8)
    '  写入数据
    MyFile.Writeline (" <TR class=tbl_body align=left> ")
    LineI = 0
    For LineI = 0 To 3
        '    写入一个网址
        If Sheets(1).Cells(n, 2) = "" Then MyFile.Writeline (" <TD width=""25%""><A href=""") + Sheets(1).Cells(n, 5) + ("""")    '写入网址连接
        If Sheets(1).Cells(n, 4) <> "" Then MyFile.Writeline (" Title = """) + Sheets(1).Cells(n, 4) + ("""")   '写入网址提示Title = ""
        If Sheets(1).Cells(n, 2) = "" Then MyFile.Writeline (" > ") + Sheets(1).Cells(n, 3) + (" </A></TD> ")      '写入网址名称
        If Sheets(1).Cells(n, 2) <> "" And LineI > 0 And LineI < 4 Then  '单个分类网址写完
            LineII = 1
            For LineII = 1 To 4 - LineI
                MyFile.Writeline (" <td width=""25%"">&nbsp;</td>")
            Next
            GoTo 20
        End If
        n = n + 1
    Next
20  Sheets(1).Cells(1, 1) = n    '位置变量
    MyFile.Writeline ("</TR> ")    '
    MyFile.Close
    Set fso = Nothing
    Set MyFile = Nothing
End Sub
Private Sub WFileTop()    '写入top
    Filename1 = ThisWorkbook.Path & "\" & "网址导航.files/top.txt"
    Filename2 = ThisWorkbook.Path & "\" & "index.html"
    Dim temp1 As Byte
    Open Filename2 For Binary As #2
    Open Filename1 For Binary As #1
    Dim i As Long
    ReDim a(1 To FileLen(Filename1))
    Do While Not EOF(1)
        Get #1, , temp1
        Put #2, , temp1
    Loop
    Close 1
    Close 2
End Sub
Public Sub WFilefoot()
    Dim fso, MyFile
    Filename = ThisWorkbook.Path & "\" & "index.html"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set MyFile = fso.OpenTextFile(Filename, 8)
    MyFile.Writeline ("  <TBODY></TBODY></TABLE>")
    MyFile.Writeline ("<SCRIPT src=""网址导航.files/foot.js""></SCRIPT>")
    MyFile.Writeline ("</BODY></HTML>")
    MyFile.Close
    Set fso = Nothing
    Set MyFile = Nothing
End Sub
Sub FileYN()    '判断AAA文件是否存在
    Set FS = Application.FileSearch
    With FS
        .LookIn = ThisWorkbook.Path            '确定路径
        .Filename = "index.html"    '查找的文件名
        If .Execute() > 0 Then   '判断查找的结果
            'MsgBox "index.html文件存在"
            Filename = ThisWorkbook.Path & "\" & "index.html"
            Kill (Filename)
            'Else
            ' MsgBox "AAA文件不存在"
        End If
    End With
End Sub

TA的精华主题

TA的得分主题

发表于 2012-8-17 15:21 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
这是干什么呢?

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-8-18 09:54 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
excel 表格内容生成 一个网页
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-23 21:17 , Processed in 0.035663 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表