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 Form_Load()
ShellExecute Me.hwnd, "open", "http://www.baidu.com", "", "", 1
End Sub
网址替换文件地址
vb如何对已经打开的word文件进行操作
首先引用 Microsoft word library
代码:
‘====================
Dim xWord As Word.Application
Private Sub CmdReplace_Click()
Dim xWord As Word.Application
Dim xRange As Range
Dim xSelection As Find
Dim xTabella As Table
Dim xCella As Cell
Set xWord = New Application
xWord.Visible = False
xWord.Documents.Add App.Path & "\新概念单词表3.rtf"
Set xRange = xWord.ActiveDocument.Range
xRange.Find.Execute "%%XXX%%", , , , , , , , , Text1.Text, True:
Set xRange = xWord.ActiveDocument.Range
xRange.Find.Execute "%%aaa%%", , , , , , , , , Text2.Text, True:
xWord.Visible = True
xWord.WindowState = wdWindowStateNormal
xWord.Application.Activate
End Sub
’================
‘"%%XXX%%" 、"%%aaa%%" 就是需要替换的内容
我的意思是先打开word再用vb操作。不是用vb打开。
vb怎么打开WORD文件?
发你百度消息。一句话简单 不用指明word安装目录就可打开
如何用VB打开word2007,例如桌面有个word2007文件,如何用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()
Open "c:\新建文档.doc" For Output As #1 '打开一WORD文档
Print #1, "这是用VB新建的文档" '
Close
ShellExecute Me.hwnd, "open", "c:\新建文档.doc", vbNullString, vbNullString, 5
End
End Sub
VB打开word
在添加代码之前应先应用,microsoft word 12.0 object library ,.具体操作--部件->引用,找到这项,选中,确定即可。
代码如下;
Dim myword As New Word.Application
Dim mydoc As Word.Document
Private Sub Command1_Click()
cd1.FileName = ""
cd1.Filter = "word文件(*.doc)|*.doc"
cd1.ShowOpen
If cd1.FileName = "" Then
Exit Sub
Else
Set myword = New Word.Application
myword.Visible = True
Set mydoc = Word.Documents.Open(cd1.FileName)
End If
End Sub
Private Sub Command2_Click()
Set myword = Nothing
Set mydoc = Nothing
End Sub
VB怎么打开WORD文档
我看你直接用ole控件来打开就可以了
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")
如何在VB中打开Word,可以直接向平时打开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
转载请注明出处51数据库 » vb打开word vb调用Word打开文档
雯雯的幸福路