⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 vb处理excel的一个源码程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   5400
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7815
   LinkTopic       =   "Form1"
   ScaleHeight     =   5400
   ScaleWidth      =   7815
   StartUpPosition =   3  '窗口缺省
   Begin VB.OptionButton Option3 
      Caption         =   "表1数据"
      Height          =   375
      Left            =   5880
      TabIndex        =   4
      Top             =   2160
      Width           =   1695
   End
   Begin VB.OptionButton Option2 
      Caption         =   "表1数据"
      Height          =   375
      Left            =   5880
      TabIndex        =   3
      Top             =   1560
      Width           =   1695
   End
   Begin VB.OptionButton Option1 
      Caption         =   "表1数据"
      Height          =   375
      Left            =   5880
      TabIndex        =   2
      Top             =   960
      Width           =   1695
   End
   Begin VB.PictureBox Picture1 
      Height          =   5175
      Left            =   0
      ScaleHeight     =   5115
      ScaleWidth      =   5595
      TabIndex        =   1
      Top             =   120
      Width           =   5655
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Read Excel"
      Height          =   375
      Left            =   5760
      TabIndex        =   0
      Top             =   240
      Width           =   1935
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'==========================================================================================================
'
' 这是一个引用Excel表格的实例
'
'
'在使用VB读取Excel内容前,你必须确认你的系统已经安装了Excel2000 或更高版本
'然后再开始菜单中引入+COM组件 Microsoft Excel Library 9.0
'
'
' 有空来我的网站看看! 有好多好东西给你下载
'
'  http://simonk.jahee.com
'
'  Simon Kong 2004-11-09
'==========================================================================================================

Dim MPath As String
Dim mApp As New Application                 '实例Excel Application
Dim mBook As New Workbook                   '实例工作簿
Dim mSheet As New Worksheet                 '实例工作表

Private Sub Command1_Click()
Dim i As Long
  Picture1.Cls
  i = 1                                     '从第一行开始读数据,直到读取第一列数据为空退出循环
  Do While mSheet.Cells(i, 1) <> ""
    Picture1.Print mSheet.Cells(i, 1) & Space(5) & mSheet.Cells(i, 2) & Space(5) & mSheet.Cells(i, 3) & Space(5) & mSheet.Cells(i, 4)
    i = i + 1
  Loop
  
End Sub

Private Sub Form_Load()
  MPath = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\")
  Set mBook = mApp.Workbooks.Open(MPath & "module.xls")
  mApp.Visible = False                      '打开的工作簿在后台执行
  Option1.Value = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
  mBook.Close False                         '关闭工作簿
  Set mSheet = Nothing
  Set mBook = Nothing
  Set mApp = Nothing
End Sub

Private Sub Option1_Click()
  Set mSheet = mBook.Worksheets("sheet1")
End Sub

Private Sub Option2_Click()
  Set mSheet = mBook.Worksheets("sheet2")
End Sub

Private Sub Option3_Click()
  Set mSheet = mBook.Worksheets("sheet3")
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -