VB输出word模板操作

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

MessageBox.Show(" " & strFileName & vbCrLf & " 无法修改, 进程将被终止 ”, “错误”,
MessageBoxButtons.OK, MessageBoxIcon.Error,
Imports System
Imports System.IO
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word
Public Class WordCaoZuo
Private WordDoc As Document
WordApp.Application.Quit(missing, missing, missing)
End Sub
'判断输出文件是否存在,存在删除
Public Function ifCunzai(ByVal strFileName As String) As Boolean
WordDoc = WordApp.Documents.Add(ObjM)
WordApp.Visible = False '不显示
' WordApp.Selection.TypeText(Text:="3654M")
End Sub
fs.Dispose()
Return False
Catch ex As Exception
Return True
End Try
End Function
End Class
WordApp.ActiveDocument.Bookmarks.IteIf
WordApp.Selection.Delete()
End Sub
'在书签位置 插入图片
WordApp = New Application
WordApp.Visible = False
Dim OpenMB As Object = CType(strTemppath, Object)
If isOpen(strTemppath) = True Then
MessageBoxDefaultButton.Button1)
Try '尝试删除文件
Select Case messageResults
Private WordApp As Application
'建立一个新的word文档
Public Sub CNewWord(strSC As String)
Dim ObjM As Object = Reflection.Missing.Value
WordApp = New Application
MessageBoxDefaultButton.Button1)
Exit Sub
End If
WordDoc = WordApp.Documents.OpenNoRepairDialog(OpenMB)
Public Sub InpPicAtBQ(ByVal strBQname As String, ByVal strPicPath As String)
'在书签 strBQname , 插入图片 strPicPath
If WordApp.ActiveDocument.Bookmarks.Exists(strBQname) = True Then
MessageBoxDefaultButton.Button1)
Return True
End Try
Else
Return False
End If
If WordApp.ActiveDocument.Bookmarks.Exists(strBQname) = True Then
WordApp.ActiveDocument.Bookmarks.Item(strBQname).Select()
End If
MessageBox.Show(" " & strTemppath & vbCrLf & " 模板文件已经打开,请关闭后再试", “警告”,
MessageBoxButtons.OK, MessageBoxIcon.Stop,
'在书签位置 替换或添加内容
Public Sub InpWzAtBQ(ByVal strBQname As String, ByVal strNeiRong As String)
' 按名称选择word中的书签“strBQname” , 并替换为“strNeiRong”
Case Else
Return True
End Select
Catch ex As Exception '如果文件存在,但又无法删除
WordApp.ActiveDocument.Bookmarks.Item(strBQname).Select()
End If
WordApp.Selection.InlineShapes.AddPicture(strPicPath)
End Sub
'WordDoc.Activate()
End Sub
'保存文档
Public Sub SaveAs(ByVal strFileName As String)
'strFileName文件名,要带路径
' 主要是省的在定义 WordDoc 了
'打开模板
Public Sub OpenMB(ByVal strTemppath As String)
Dim Missing As Object = Type.Missing
'object Missing = System.Reflection.Missing.Value;
End Function
'判断文档 是否已经打来
Private Function isOpen(ByVal path_string As String) As Boolean
Try
Dim fs As New FileStream(path_string, FileMode.OpenOrCreate, FileAccess.Read)
'判断是否存在输出的文件
'不能替换或生成 返回值True 呵呵 不成立返回值为true
If File.Exists(strFileName) Then
Dim messageResults As DialogResult
Dim fileName As Object = strFileName
WordDoc.SaveAs(fileName)
End Sub
'退出
Public Sub Quit()
Dim missing As Object = System.Reflection.Missing.Value
Case DialogResult.Yes '如果按的是 yes
File.Delete(strFileName)
Return False
messageResults = MessageBox.Show(" " & strFileName & vbCrLf & " 文件已经存在,是否替换", “警告”,
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
WordApp.Selection.TypeText(strNeiRong)
End Sub
'在书签位置 删除书签选定的内容
Public Sub DeleBQ(ByVal strBQname As String)
If WordApp.ActiveDocument.Bookmarks.Exists(strBQname) = True Then
相关文档
最新文档