Dim wordApp As New Microsoft.Office.Interop.Word.Application Dim wordDoc As New Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Open(DirListBox1.Path & "\" & fileArrayComList(i, 0)) '打开文件并赋予文件实例 If Err.Number = 462 Then wordApp = CreateObject("Word.Application") '建立WORD实例 wordDoc = wordApp.Documents.Open(DirListBox1.Path & "\" & fileArrayComList(i, 0)) '打开文件并赋予文件实例 End If Dim stringDoc = wordDoc.Range.Text Do While InStr(stringDoc, Chr(10) & Chr(13)) > 0 stringDoc = stringDoc.replace(Chr(13), "<br><br> ") Loop stringDoc = stringDoc.replace(" ", " ") stringDoc = stringDoc.replace(" ", "") stringDoc = stringDoc.replace("'", "‘") 'MsgBox(stringDoc) wordDoc.Close() '关闭文档实例 wordApp.Quit() wordDoc = Nothing wordApp = Nothing '模块代码 Type docit name As String paragraph As Long allcount As Long reblank As Long resign As Long End Type '主程序代码 Dim itemDoc As docit Dim stringDoc As String Dim k As Integer Dim wordCount() Dim wordApp As New Word.Application Dim wordDoc As New Word.Document Dim wordArange As Word.Range Dim wordSelection As Word.Selection Dim ReplaceSign As Boolean 's为文件名及地址 On Error Resume Next Set wordDoc = wordApp.Documents.Open(s) '打开文件并赋予文件实例 If Err.Number = 462 Then Set wordApp = CreateObject("Word.Application") '建立WORD实例 Set wordDoc = wordApp.Documents.Open(s) '打开文件并赋予文件实例 End If On Error GoTo ss 'itemDoc.name = wordDoc.Words.Parent stringDoc = wordDoc.Range.Text itemDoc.paragraph = 0 itemDoc.allcount = Len(stringDoc) wordDoc.Close '关闭文档实例
费哪精神干什么 很多机器上默认安装有 Microsoft Office Document Image Writer 打印机 可以直接打印成TIF文件
你试试吧 Dim a() As String * 200 Dim i As IntegerPrivate Sub Command1_Click() '50行一页存到p1 图形框中 On Error GoTo gg Dim kk As Integer For kk = 1 + (Val(Text2.Text) - 1) * 50 To 50 * Val(Text2.Text) 'text2.text 为要存到图片上的当前页数,如输入1,2,3页 ReDim Preserve a(50) P1.Print a(kk) Next kk Exit Sub gg: MsgBox "请在text2内输入页数,不要超过总页数": Exit Sub End SubPrivate Sub Command2_Click() '保存到图片文件On Error GoTo ggC1.CancelError = True C1.FileName = "" C1.Filter = "(*.bmp)|*.bmp" C1.Action = 2SavePicture P1.Image, C1.FileName gg: Exit Sub End SubPrivate Sub Command3_Click() '打开文件,送数组a(i),i 为文件总行数 On Error GoTo gg C1.CancelError = True C1.Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt C1.Filter = "(*.txt)|*.txt|(*.doc)|*.doc|(All*.*)|*.*" C1.DialogTitle = "文件打开" & Date & Time C1.Action = 1 Open C1.FileName For Input As #1 Do While Not EOF(1) ReDim Preserve a(i) Line Input #1, a(i)i = i + 1 Loop Close #1 Text1.Text = i \ 50 + 1 '打开的总页数送text1.text显示,以50行为例,也可以是别的,具体你的p1依次可以显示多少行,相应该就可以 gg: Exit Sub End SubPrivate Sub Form_Load() Text1.Text = "" Text2.Text = "" End Sub 其中p1为picturebox ,c1为commondialog 工程部件中添加microsot common dialog control 6.0
Dim wordApp As New Microsoft.Office.Interop.Word.Application
Dim wordDoc As New Microsoft.Office.Interop.Word.Document
wordDoc = wordApp.Documents.Open(DirListBox1.Path & "\" & fileArrayComList(i, 0)) '打开文件并赋予文件实例
If Err.Number = 462 Then
wordApp = CreateObject("Word.Application") '建立WORD实例
wordDoc = wordApp.Documents.Open(DirListBox1.Path & "\" & fileArrayComList(i, 0)) '打开文件并赋予文件实例
End If Dim stringDoc = wordDoc.Range.Text
Do While InStr(stringDoc, Chr(10) & Chr(13)) > 0
stringDoc = stringDoc.replace(Chr(13), "<br><br> ")
Loop
stringDoc = stringDoc.replace(" ", " ")
stringDoc = stringDoc.replace(" ", "")
stringDoc = stringDoc.replace("'", "‘")
'MsgBox(stringDoc)
wordDoc.Close() '关闭文档实例
wordApp.Quit()
wordDoc = Nothing
wordApp = Nothing
'模块代码
Type docit
name As String
paragraph As Long
allcount As Long
reblank As Long
resign As Long
End Type
'主程序代码
Dim itemDoc As docit
Dim stringDoc As String
Dim k As Integer
Dim wordCount()
Dim wordApp As New Word.Application
Dim wordDoc As New Word.Document
Dim wordArange As Word.Range
Dim wordSelection As Word.Selection
Dim ReplaceSign As Boolean
's为文件名及地址
On Error Resume Next
Set wordDoc = wordApp.Documents.Open(s) '打开文件并赋予文件实例
If Err.Number = 462 Then
Set wordApp = CreateObject("Word.Application") '建立WORD实例
Set wordDoc = wordApp.Documents.Open(s) '打开文件并赋予文件实例
End If
On Error GoTo ss
'itemDoc.name = wordDoc.Words.Parent
stringDoc = wordDoc.Range.Text
itemDoc.paragraph = 0
itemDoc.allcount = Len(stringDoc)
wordDoc.Close '关闭文档实例
picture1.printer a(i)应该改成picture1.print a(i)
打开文件,每一行送数组,计算picture1高度(可以打印多少行),picture1.print a(i) 统计a(i)总数/可以打印多少行,统计出多少页,想打印哪页,就打印数组的范围即可,然后保存成图片文件.
Picture1.CurrentY可以决定打印当前的位置.
很多机器上默认安装有 Microsoft Office Document Image Writer 打印机
可以直接打印成TIF文件
Dim a() As String * 200
Dim i As IntegerPrivate Sub Command1_Click() '50行一页存到p1 图形框中
On Error GoTo gg
Dim kk As Integer
For kk = 1 + (Val(Text2.Text) - 1) * 50 To 50 * Val(Text2.Text) 'text2.text 为要存到图片上的当前页数,如输入1,2,3页
ReDim Preserve a(50)
P1.Print a(kk)
Next kk
Exit Sub
gg: MsgBox "请在text2内输入页数,不要超过总页数": Exit Sub
End SubPrivate Sub Command2_Click() '保存到图片文件On Error GoTo ggC1.CancelError = True
C1.FileName = ""
C1.Filter = "(*.bmp)|*.bmp"
C1.Action = 2SavePicture P1.Image, C1.FileName
gg: Exit Sub
End SubPrivate Sub Command3_Click() '打开文件,送数组a(i),i 为文件总行数
On Error GoTo gg
C1.CancelError = True
C1.Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt
C1.Filter = "(*.txt)|*.txt|(*.doc)|*.doc|(All*.*)|*.*"
C1.DialogTitle = "文件打开" & Date & Time
C1.Action = 1
Open C1.FileName For Input As #1
Do While Not EOF(1)
ReDim Preserve a(i)
Line Input #1, a(i)i = i + 1
Loop
Close #1
Text1.Text = i \ 50 + 1 '打开的总页数送text1.text显示,以50行为例,也可以是别的,具体你的p1依次可以显示多少行,相应该就可以
gg: Exit Sub
End SubPrivate Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub
其中p1为picturebox ,c1为commondialog 工程部件中添加microsot common dialog control 6.0
将p1属性中AutoRedraw设置成True 在属性设置即可 如果是false无法保存成图片
Dim stringDoc = wordDoc.Range.Text 这能通过吗?????还有是不是要引用什么 你没写出来 不然 NEW Microsoft.Office.Interop.Word.Application == 是不能通过。