依据:
http://msdn.microsoft.com/zh-cn/library/7t9k08y5(v=VS.80).aspx
CreateObject 函数 (Visual Basic)
http://msdn.microsoft.com/zh-cn/library/e9waz863(VS.80).aspx
GetObject 函数 (Visual Basic)以MSDN介绍的Excel为例,讨论的问题如下:
1 test.xls是否存在(指定路径).
2 test.xls是否打开(避免重复打开)
3 test.xls如果没有打开,打开test.xls现在网上有很多VB无缝控制Excel程序有很多问题
最突出的问题,就是CreateObject + Add方法,结果是打开了N个Excel
发此帖的目的是希望各位大侠积极参与,小结一个通用的方法,实现CreateObject+GetObject在各个应用程序中的应用.
如word Ppt cad中的应用,道理都是一样的.Private Sub getExcel()
Dim fileName As String = "c:\vb\test.xls" If Not My.Computer.FileSystem.FileExists(fileName) Then
MsgBox(fileName & " does not exist")
Exit Sub
End If ' Set the object variable to refer to the file you want to use.
Dim excelObj As Object = GetObject(fileName)
' Show Excel through its Application property.
excelObj.Application.Visible = True
' Show the window containing the file.
Dim winCount As Integer = excelObj.Parent.Windows.Count()
excelObj.Parent.Windows(winCount).Visible = True ' Insert additional code to manipulate the test.xls file here.
' ... excelObj = Nothing
End Sub
http://msdn.microsoft.com/zh-cn/library/7t9k08y5(v=VS.80).aspx
CreateObject 函数 (Visual Basic)
http://msdn.microsoft.com/zh-cn/library/e9waz863(VS.80).aspx
GetObject 函数 (Visual Basic)以MSDN介绍的Excel为例,讨论的问题如下:
1 test.xls是否存在(指定路径).
2 test.xls是否打开(避免重复打开)
3 test.xls如果没有打开,打开test.xls现在网上有很多VB无缝控制Excel程序有很多问题
最突出的问题,就是CreateObject + Add方法,结果是打开了N个Excel
发此帖的目的是希望各位大侠积极参与,小结一个通用的方法,实现CreateObject+GetObject在各个应用程序中的应用.
如word Ppt cad中的应用,道理都是一样的.Private Sub getExcel()
Dim fileName As String = "c:\vb\test.xls" If Not My.Computer.FileSystem.FileExists(fileName) Then
MsgBox(fileName & " does not exist")
Exit Sub
End If ' Set the object variable to refer to the file you want to use.
Dim excelObj As Object = GetObject(fileName)
' Show Excel through its Application property.
excelObj.Application.Visible = True
' Show the window containing the file.
Dim winCount As Integer = excelObj.Parent.Windows.Count()
excelObj.Parent.Windows(winCount).Visible = True ' Insert additional code to manipulate the test.xls file here.
' ... excelObj = Nothing
End Sub
解决方案 »
- excel与记事本for next循环切换。
- 我已经写好一个画图的OCX控件,如何才能转换成像微软的OWC控件一样,可以有直接直接导出图片EXPORTPICTURE的功能?
- 急求ISO-8859-1到GB/GBK的转换方法
- 郁闷点vb基础类出现:文本内容中发现无效字符
- 简单问题,但有疑问?有空的进来瞧瞧
- vb能不能做程序多开的东西?
- 各位 介绍几个程序员找工作的网站好吗 ??谢谢了!!
- 如何读取硬盘的序列号?
- 有谁知道sourcesafe中如何实现两文本的Show Differences??
- 求救,在form1主窗体中点击关闭按钮“x”只是卸载窗体,不关闭程序,如何设置才关闭程序?
- MSHFlexGrid中单击某一行变色,如何实现
- 由英文字母、数字和空格组成
另外这个应该是VB.NET 2005+的程序,怎么跑到VB板块来了。
怪不得,这些代码帖到VB,无法运行.原来是VB.NET