form1.frm

来自「利用VB控制WORD输入文字」· FRM 代码 · 共 62 行

FRM
62
字号
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   1560
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4005
   LinkTopic       =   "Form1"
   ScaleHeight     =   1560
   ScaleWidth      =   4005
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command2 
      Caption         =   "加入文字"
      Height          =   495
      Left            =   2400
      TabIndex        =   2
      Top             =   240
      Width           =   1215
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   240
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   960
      Width           =   3615
   End
   Begin VB.CommandButton Command1 
      Caption         =   "打开Word"
      Height          =   495
      Left            =   360
      TabIndex        =   0
      Top             =   240
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim MyWord As Object
Dim NewDoc As Object
Dim NewObj As Worksheet
Dim astr As String
    
Private Sub Command1_Click()
    Set MyWord = CreateObject("Word.Application")
    MyWord.Visible = True
    MyWord.Caption = "This word sample"
    Set NewDoc = Nothing
End Sub

Private Sub Command2_Click()
    Set NewDoc = MyWord.Documents.Add
    NewDoc.Paragraphs(1).Range.Text = "Ok,This is my first samples"
End Sub

Private Sub Form_Unload(Cancel As Integer)
    MyWord.Quit
End Sub

⌨️ 快捷键说明

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