在vb中调用word或excel文档,怎样实现?
我需要在程序中通过点击文本连接调用word或者excel文档,请问怎样实现,谢谢!
我需要在程序中通过点击文本连接调用word或者excel文档,请问怎样实现,谢谢!
解决方案 »
- microsoft activex data objects 2.8 和 6.0 哪版本个新
- 如何通过Twain API 调用来驱动扫描仪进行扫描
- 高手的运动场:已知一种语言的unicode范围,如何获得相对应的文字!!!
- ***vb下如何让程序窗体自动适应分辨率?(高分奉送)
- VB如何连接oracle数据库?(我是初学者)
- 请各位高人看一下,编译《vb数据库系统开发实例导航》的代码出现的问题!!!!
- 请问有没有 VBA 专栏 ???
- vb中如何实现运行时候拖动鼠标改变控件大小?
- Vb+Sql server OLAP Server 的问题,win98如何支持更新立方体?
- 请教,谢谢!
- vb中实现对word的编辑
- OA系统问题
就是打开word , excel 并打开某个文件是吗?1,在project\references 中加入microsoft word 9.0 object library2, 启动word
Dim wApp As Word.Application
Set wApp = New Word.Application
wApp.Visible = True
关闭word
wApp.Quit
Set wApp = Nothing3, 打开文件
Set wDoc = wapp.Documents.Add (新建)
wapp.ActiveDocument.SaveAs Text1.Text (保存)
Set wDoc = wapp.Documents.Open(FileName:=Text1.Text) (打开指定文件)excel 文件 也可以类似的写
Dim WordApp As New Word.Application
Dim wDoc As Document
Dim wTable As Word.Table
Set wDoc = WordApp.Documents.Open("E:\yours\cdkgood1.doc") '路径自己选择
Set wTable = wDoc.Tables(1) '取第一个表格,这里最好判断一下有没有表格,呵呵
MsgBox wTable.Cell(1, 1) '取表的第一行第一列,最好也对行和列作有效判断
WordApp.Quit '这一句是退出
Set wTable = Nothing
Set wDoc = Nothing
Set WordApp = Nothing
End Sub下面例子复制excel 中第一个sheet复制到同一个excel文件的最后并起名为 my new sheetdim xlSheet as Excel.Worksheet
dim xlBook as Excel.WordBook
dim xlApp as Excel.Application
set xlApp = new Excel.Application
set xlBook = xlApp.WorkBooks.Add("你的excel文件名包括路径") '打开你要的文件
xlBook.sheets(1).Activate
set xlSheet = xlBook.AcitveSheet
xlSheet.Select
xlSheet.Copy After:=xlBook.Sheets(xlBook.Sheets.Count)
set xlSheet = xlBook.ActiveSheet ’复制Sheet1
xlSheet.select
xlSheet.Name = "my new sheet"
xlSheet.cell(1.2)="Text" '单元格1行,2列的值为:Text
xlSheet.range("B3:B4")="Text2" '单元格B3到B4的值为:Text2
xlApp.Visable = True
Set xlSheet = nothing
Set xlBook = nothing
Set xlApp = nothing
Set wrdApp = New Word.Application '写word文档
With wrdApp
'Show Word
.Visible = True
'Create New Document
.Documents.Add
'Add text to the document
.ActiveDocument.Content.Text = "Hello"
.ActiveDocument.Content.Text = "This is a test example"
.Documents.Save
End With
End Sub
Dim sFileName, sContent, sPartContent As String '打开word文档并画一个方框
Dim wrdApp As Object
Dim k As String
CommonDialog1.ShowOpen
If Err <> 0 Then Exit Sub
sFileName = CommonDialog1.FileName
If sFileName = "" Then Exit Sub
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
wrdApp.Documents.Open (sFileName)
wrdApp.ActiveDocument.Shapes.AddTextbox Orientation:=msoTextOrientationHorizontal, Left:=100, Top:=100, Width:=300, Height:=200
wrdApp.ActiveDocument.Shapes(1).TextFrame.TextRange = "ee"
'sContent = wrdApp.ActiveDocument.Content
wrdApp.Documents.Save
End Sub