1.VB如何读入Word的内容
Set oApp = CreateObject("Word。
Application") oApp。Visible = False Set oDoc = oApp。
Documents。Open(strFile)'strFile为文件路径 '获得最后一段的内容 Dim length As Long '整个文档的长度 Dim i As Long length = oDoc。
Content。StoryLength Content = oDoc。
Content。Text Dim s As String For i = 1 To length If Mid$(Content, i, 1) = Chr$(13) Then s = s + vbCrLf Else s = s + Mid$(Content, i, 1) End If Next i oDoc。
Close True oApp。Quit False txtMx = s。
2.vb 调用Word打开文档
引用CommonDialog和Microsoft Word 11.0 object Libary(其他版本也行,看机器情况)
Private Sub Command1_Click()
Dim DocPath As String
Dim wApp As New Word.Application
CommonDialog1.ShowOpen
DocPath = CommonDialog1.FileName
If DocPath = "" Then wApp.Documents.Close: Set wApp = Nothing
wApp.Documents.Open DocPath
wApp.Visible = True
End Sub
Private Sub Form_Load()
CommonDialog1.Filter = "Word文档 (*.dco)|*.doc"
CommonDialog1.DialogTitle = "选择要打开的文档"
CommonDialog1.CancelError = False
End Sub
3.vb 打开word文件
请把以下代码贴到模块中:Private Declare Function GetDesktopWindow Lib "user32" () As LongPrivate Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1Public Function OpenFile(asPath As String,optional PramCommand as string) As Long
On Error Resume Next
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
If Len(asPath) = 0 Then Exit Function OpenFile = ShellExecute(Scr_hDC, "Open", asPath, PramCommand, "C:\", SW_SHOWNORMAL)
End Function 如果要打开word,直接调用Call OpenFile("C:\Program Files\a\a.doc")或者Call OpenFile(C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE,"C:\Program Files\a\a.doc")
4.VB直接打开word问题
使用APi函数吧,Open语句比较繁琐。
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Sub Command1_Click()ShellExecute Me.hwnd, "Open", App.Path & "\homwork.doc", vbNullString, vbNullString, vbNormalFocusEnd Sub Open 语句是不能打开Word文档的,即使打开也是乱码。 Open语句使用方法: Open 语句 能够对文件输入/输出 (I/O)。
语法 Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength] Open 语句的语法具有以下几个部分: 部分 描述 pathname 必要。字符串表达式,指定文件名,该文件名可能还包括目录、文件夹及驱动器。
mode 必要。关键字,指定文件方式,有 Append、Binary、Input、Output、或 Random 方式。
如果未指定方式,则以 Random 访问方式打开文件。 access 可选。
关键字,说明打开的文件可以进行的操作,有 Read、Write、或 Read Write 操作。 lock 可选。
关键字,说明限定于其它进程打开的文件的操作,有 Shared、Lock Read、Lock Write、和 Lock Read Write 操作。 filenumber 必要。
一个有效的文件号,范围在 1 到 511 之间。使用 FreeFile 函数可得到下一个可用的文件号。
reclength 可选。小于或等于 32,767(字节)的一个数。
对于用随机访问方式打开的文件,该值就是记录长度。对于顺序文件,该值就是缓冲字符数。
说明 对文件做任何 I/O 操作之前都必须先打开文件。Open 语句分配一个缓冲区供文件进行 I/O 之用,并决定缓冲区所使用的访问方式。
如果 pathname 指定的文件不存在,那么,在用 Append、Binary、Output、或 Random 方式打开文件时,可以建立这一文件。 如果文件已由其它进程打开,而且不允许指定的访问类型,则 Open 操作失败,而且会有错误发生。
如果 mode 是 Binary 方式,则 Len 子句会被忽略掉。 重要 在 Binary、Input 和 Random 方式下可以用不同的文件号打开同一文件,而不必先将该文件关闭。
在 Append 和 Output 方式下,如果要用不同的文件号打开同一文件,则必须在打开文件之前先关闭该文件。 我不明白你是要做什么?所以只能提供shell 函数使用方法 shell函数使用方法: Shell 函数 执行一个可执行文件,返回一个 Variant (Double),如果成功的话,代表这个程序的任务 ID,若不成功,则会返回 0。
语法 Shell(pathname[,windowstyle]) Shell 函数的语法含有下面这些命名参数: 部分 描述 pathname 必要参数。Variant (String),要执行的程序名,以及任何必需的参数或命令行变量,可能还包括目录或文件夹,以及驱动器。
Windowstyle 可选参数。Variant (Integer),表示在程序运行时窗口的样式。
如果 windowstyle 省略,则程序是以具有焦点的最小化窗口来执行的。 windowstyle 命名参数有以下这些值: 常量 值 描述 vbHide 0 窗口被隐藏,且焦点会移到隐式窗口。
VbNormalFocus 1 窗口具有焦点,且会还原到它原来的大小和位置。 VbMinimizedFocus 2 窗口会以一个具有焦点的图标来显示。
VbMaximizedFocus 3 窗口是一个具有焦点的最大化窗口。 VbNormalNoFocus 4 窗口会被还原到最近使用的大小和位置,而当前活动的窗口仍然保持活动。
VbMinimizedNoFocus 6 窗口会以一个图标来显示。而当前活动的的窗口仍然保持活动。
说明 如果 Shell 函数成功地执行了所要执行的文件,则它会返回程序的任务 ID。任务 ID 是一个唯一的数值,用来指明正在运行的程序。
如果 Shell 函数不能打开命名的程序,则会产生错误。 注意 缺省情况下,Shell 函数是以异步方式来执行其它程序的。
也就是说,用 Shell 启动的程序可能还没有完成执行过程,就已经执行到 Shell 函数之后 例子: 打开系统的计算器 Dim RetVal RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)。
5.vb按钮怎么打开一个word文挡啊求一个vb小程序就是里面有一个
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Private Sub Command1_Click() ShellExecute Me.hwnd, "Open", "D:\test.doc", "", App.Path, 1 End Sub。
6.在VB中如何打开WORD等程序
(转载)这个问题在VB吧讨论过,怎么可能一个程序让你这样打开呢?那么编译就没有必要了。
说实话,很简单,编译就是为了保密。比如你的一个程序需要输入密码,你写了: If txt.Text = "123456" Then Msgbox "密码正确" Else Msgbox "错误" End If 如果别人有VB,就打开了你的程序??还有保密性吗?要序列号干什么? 想打开,必须反编译。
对一个新手程序员,是不太可能做到的。这个需要大量的经验。
现在对于您,可以做的,就是去找源码(就是VB的存档)。你上网搜索,基本上可以找到的。
7.在VB中如何打开WORD等程序
(转载)
这个问题在VB吧讨论过,怎么可能一个程序让你这样打开呢?那么编译就没有必要了。
说实话,很简单,编译就是为了保密。比如你的一个程序需要输入密码,你写了:
If txt.Text = "123456" Then
Msgbox "密码正确"
Else
Msgbox "错误"
End If
如果别人有VB,就打开了你的程序??还有保密性吗?要序列号干什么?
想打开,必须反编译。对一个新手程序员,是不太可能做到的。这个需要大量的经验。
现在对于您,可以做的,就是去找源码(就是VB的存档)。你上网搜索,基本上可以找到的。
8.如何用VB打开一WORD文档
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
Open "c:\新建文档.doc" For Output As #1 '打开一WORD文档
Print #1, "这是用VB新建的文档" '
Close
ShellExecute Me.hwnd, "open", "c:\新建文档.doc", vbNullString, vbNullString, 5
End
End Sub
9.用VB打开一个已存在的word文档并向其中插入指定文本
Dim oWord As Word.Application
Dim oDocument As Word.Document
Dim nRet As Integer
On Error GoTo ErrOpen
Set oWord = New Word.Application
' If FileName = "" Then
' Set oDocument = oWord.Documents.Add
' Else
Set oDocument = oWord.Documents.Open("e:\test1.doc")'要打开的文件名
' End If
oWord.Visible = True '如果不想看见WORD窗口,可以设为false
'将text插入到最后
oDocument.Paragraphs.Last.Range.InsertAfter Text1.Text
OpenDocument = 1
GoTo ExitOpen
ErrOpen:
OpenDocument = 0
ExitOpen:
oDocument.Save '保存文档
oWord.Quit '退出WORD
Set oDocument = Nothing
Set oWord = Nothing