在vb的"工程"->"引用" 中引用word 或excel dim excel as object dim workbook as object dim worksheet as objectSet excel = CreateObject("excel.application") Set workbook = excel.Workbooks.Open(App.Path & "\temp.xls") Set worksheet = workbook.ActiveSheet excel.Visible = True
darkeye!把你的代码写下来看看! 如果我打开是word文档,怎写!?
Public 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 ShellExecute 0,"OPEN",yourFileName,0,0,1
Dim word As Object Dim documents As Object Private Sub Command1_Click() Set word = CreateObject("word.application") Set documents = word.documents.Open("c:\temp.doc") word.Visible = True End Sub注意要先VB的"工程"->"引用" 中引用Microsoft word 9.0 object library
那打开access数据库呢?还有其他的txt文件!!!
zzzwww(岩上居者) :你的代码好像不行的了?! Public 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 Command3_Click() ShellExecute 0, "OPEN", "c:\p.doc", 0, 0, 1 End Sub
dim excel as object
dim workbook as object
dim worksheet as objectSet excel = CreateObject("excel.application")
Set workbook = excel.Workbooks.Open(App.Path & "\temp.xls")
Set worksheet = workbook.ActiveSheet
excel.Visible = True
如果我打开是word文档,怎写!?
ShellExecute 0,"OPEN",yourFileName,0,0,1
Dim documents As Object
Private Sub Command1_Click()
Set word = CreateObject("word.application")
Set documents = word.documents.Open("c:\temp.doc")
word.Visible = True
End Sub注意要先VB的"工程"->"引用" 中引用Microsoft word 9.0 object library
Public 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 Command3_Click()
ShellExecute 0, "OPEN", "c:\p.doc", 0, 0, 1
End Sub
yourFileName为你要打开的文件名。
该函数可打开任意有关联打开方式的文件。