vb保存为html,能把WORD文件用VB转存为html吗

能把WORD文件用VB转存为html吗?具体怎么实现?

楼主hitler45(Jery)2002-12-0911:03:17在VB/VBA提问

能把WORD文件用VB转存为html吗?具体怎么实现?问题点数:100、回复次数:4

1楼henrryzhang(NorthWolf)回复于2002-12-0911:08:12得分100

VB中引用WORD对象后用以下的语句保存即可

ActiveDocument.SaveAs FileName:="asdfgasdfsdsdffsd.htm", FileFormat:= _

wdFormatFilteredHTML, LockComments:=False, Password:="", AddToRecentFiles _

:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _

:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _

SaveAsAOCELetter:=False

==========================================================================================================

把.doc打开后,另存为.html:

ActiveDocument.SaveAs FileName:= "Test.htm ", FileFormat:=wdFormatHTML, _

LockComments:=False, Password:= " ", AddToRecentFiles:=True, WritePassword _

:= " ", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _

SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _

False

======================================================================================================

'引用Microsoft Word X.0 Object Library

Private Sub Command1_Click()

On Error GoTo connecterr

Dim wordApp As Object

Set wordApp = CreateObject( "word.application ")

wordApp.Visible = True

Dim myDoc As Object

Set myDoc = wordApp.Documents.Open( "c:\Test.dot ")

myDoc.SaveAs FileName:= "Test.htm ", FileFormat:=wdFormatHTML, _

LockComments:=False, Password:= " ", AddToRecentFiles:=True, WritePassword _

:= " ", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _

SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _

False

myDoc.Close

wordApp.Quit

Set myDoc = Nothing

Set wordApp = Nothing

Exit Sub

connecterr:

End Sub

=======================================================================================================

Set mwa = New Word.Application

Dim sFileName As String

sFileName = App.Path & "/aaa.doc "

mwa.Documents.Open sFileName, , , , , , , , , , False

mwa.Visible = True

mwa.ChangeFileOpenDirectory App.Path

mwa.ActiveDocument.SaveAs App.Path & "/aaa.htm ", wdFormatHTML, False,

" ", True, " ", False, False, False, False, False

ActiveWindow.View.Type = wdWebView

mwa.ActiveDocum

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 以下是 VB6 代码示例,用于将文本内容保存为 UTF-8 编码的文本文件: ```vb Private Sub SaveAsUTF8(strContent As String, strFilePath As String) Dim iFileNum As Integer iFileNum = FreeFile() Open strFilePath For Output As #iFileNum Print #iFileNum, strContent Close #iFileNum End Sub ``` 使用方法: ```vb SaveAsUTF8 "你好,世界", "C:\example.txt" ``` 该代码使用 VB6 的 "Open" 和 "Print" 命令在指定路径上创建文本文件,并使用 "Close" 命令关闭文件。在保存文本时,编码默认为 UTF-8。 ### 回答2: 在VB6中,要将文本保存为UTF-8编码的文件,可以使用FileSystemObject对象的CreateTextFile方法,并设置FileFormat属性为Unicode。 以下是一个示例代码: ```vb Dim fs As New FileSystemObject Dim file As TextStream Set file = fs.CreateTextFile("C:\path\to\output.txt", True, False) ' 第一个参数为保存文件的路径 file.Write "这是一段UTF-8编码的文本" ' 要保存的文本内容 file.Close Set file = Nothing Set fs = Nothing ``` 在上述示例中,使用FileSystemObject创建了一个TextStream对象,并传入CreateTextFile方法中的第一个参数指定了保存文件的路径。然后,可以使用TextStream对象的Write方法将要保存的文本内容写入文件中,最后使用Close方法关闭文件。 请注意,VB6的FileSystemObject使用的是系统默认编码。要将文本保存为UTF-8编码的文件,需要将文件另存为UTF-8格式。可以在保存文件的对话框中选择“保存类型”为"Unicode文本(.txt)",然后手动修改文件扩展名为".txt"。 ### 回答3: 在VB6保存文本文件为UTF-8编码可以借助FileSystemObject对象来实现。以下是一个示例代码: ```vba Dim fs As Object Dim file As Object Dim text As String ' 创建文件系统对象 Set fs = CreateObject("Scripting.FileSystemObject") ' 创建文本文件 Set file = fs.CreateTextFile("C:\path\to\file.txt", True) ' 设置文件编码为UTF-8 file.Write ChrW(&HFEFF) ' 读取要保存的文本内容 text = "这是要保存的文本内容" ' 将文本内容写入文件 file.Write text ' 关闭文件 file.Close ' 释放对象 Set file = Nothing Set fs = Nothing ``` 代码中,首先创建一个FileSystemObject对象,然后使用CreateTextFile方法创建了一个文本文件,并且设置了文件编码为UTF-8。接下来将要保存的文本内容写入文件,并且最后关闭文件。 请注意,该示例中使用的是Late Binding方式,你也可以使用引用方式来导入Scripting Runtime库,以获得更好的代码提示和类型检查。另外,示例代码中的文件路径需要根据实际情况进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值