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

📄 form1.frm

📁 本程序是一个数据库格式转化系统,可以把EXCESS里面的数据在顷刻间转化成ACESS的形式,为您在EXCESS的基础上编译程序节约时间
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "复制EXCEL数据到ACCESS"
   ClientHeight    =   1590
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5760
   LinkTopic       =   "Form1"
   ScaleHeight     =   1590
   ScaleWidth      =   5760
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtAccessFile 
      Height          =   285
      Left            =   1560
      TabIndex        =   3
      Top             =   480
      Width           =   4095
   End
   Begin VB.CommandButton cmdLoad 
      Caption         =   "数据复制"
      Default         =   -1  'True
      Height          =   495
      Left            =   2280
      TabIndex        =   2
      Top             =   960
      Width           =   1215
   End
   Begin VB.TextBox txtExcelFile 
      Height          =   285
      Left            =   1560
      TabIndex        =   1
      Top             =   120
      Width           =   4095
   End
   Begin VB.Label Label1 
      Caption         =   "ACCESS文件"
      Height          =   255
      Index           =   1
      Left            =   120
      TabIndex        =   4
      Top             =   480
      Width           =   1335
   End
   Begin VB.Label Label1 
      Caption         =   "EXCEL文件"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   1335
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit
'数据复制按钮单击事件
Private Sub cmdLoad_Click()
Dim excel_app As Object
Dim excel_sheet As Object
Dim db As Database
Dim new_value As String
Dim row As Integer

    Screen.MousePointer = vbHourglass
    DoEvents

    '创建Excel应用程序对象
    Set excel_app = CreateObject("Excel.Application")

    '打开Excel文件
    excel_app.Workbooks.Open FileName:=txtExcelFile.Text

    '检查最新的版本
    If Val(excel_app.Application.Version) >= 8 Then
        Set excel_sheet = excel_app.ActiveSheet
    Else
        Set excel_sheet = excel_app
    End If

    ' 打开ACCESS数据库
    Set db = OpenDatabase(txtAccessFile.Text)

    ' 获得Excel数据,并插入到Access数据库表中
    row = 1
    Do
        '获得下一个值
        new_value = Trim$(excel_sheet.Cells(row, 1))

        '检查是否是空值
        If Len(new_value) = 0 Then Exit Do

        '将值插入到表中
        db.Execute "INSERT INTO TestValues VALUES (" & _
            new_value & ")"

        row = row + 1
    Loop

    ' 关闭数据库
    db.Close
    Set db = Nothing

 
    ' 设定关闭Excel的时候,不保存
    excel_app.ActiveWorkbook.Close False

    '关闭Excel,并释放资源
    excel_app.Quit
    Set excel_sheet = Nothing
    Set excel_app = Nothing

    Screen.MousePointer = vbDefault
    MsgBox "Copied " & Format$(row - 1) & " values."
End Sub
'窗体载入事件
' 本程序需要引用 DAO 3.51 Object Library
Private Sub Form_Load()
Dim file_path As String

    file_path = App.Path
    If Right$(file_path, 1) <> "\" Then file_path = file_path & "\"
    '初始化excel和access路径,如果改成其他文件,注意实现的程序也要改变
    txtExcelFile.Text = file_path & "XlsToMdb.xls"
    txtAccessFile.Text = file_path & "XlsToMdb.mdb"
End Sub


⌨️ 快捷键说明

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