form1.frm

来自「VB essential experience VB essential ex」· FRM 代码 · 共 71 行

FRM
71
字号
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3090
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3090
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "end"
      Height          =   435
      Left            =   2400
      TabIndex        =   1
      Top             =   480
      Width           =   1575
   End
   Begin VB.CommandButton Command1 
      Caption         =   "excel"
      Height          =   495
      Left            =   480
      TabIndex        =   0
      Top             =   480
      Width           =   1575
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
 
 Option Explicit
 Dim xlapp As Excel.Application
 Dim xlbook As Excel.Workbook
 Dim xlsheet As Excel.Sheets
 

Private Sub Command1_Click()
 If Dir("D:\temp\excel.bz") = "" Then
 Set xlapp = CreateObject("excel.application")
 xlapp.Visible = True
 Set xlbook = xlapp.Workbooks.Open("D:\temp\bb.xls")
 Set xlsheet = xlbook.Worksheets(1)
 xlsheet.Cells(1, 1) = "abc"
 xlbook.RunAutoMacros (xlAutoOpen)
 Else
 MsgBox ("excel已打开")
 End If
 



End Sub

Private Sub Command2_Click()
If Dir("D:\temp\excel.bz") <> "" Then
xlbook.RunAutoMacros (xlAutoClose)
xlbook.Close (True)
xlapp.Quit
End If
Set xlapp = Nothing '释放EXCEL对象
  End



End Sub

⌨️ 快捷键说明

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