VBA 如何打开Word时弹出对话框? 如何在页眉中的表格中插入值?

'当打开Word时弹出对话框 要用户输入内容
Private Sub Document_Open()
'    MsgBox "asaaaaaaaaaaaa"
    AddHeader.Show
End Sub

点击按钮后弹出页面
Private Sub CommandButton3_Click()
    AddHeader.Show
End Sub

'''''''''''''''''''''--------------------------------------------------
Private Sub CmdClear_Click()
TxtFileName.Value = ""
TxtID.Value = ""
TxtSecrecy.Value = ""
TxtRev.Value = ""

End Sub

//在页眉中的表格中插入值.
Private Sub CommandButton1_Click()

With ActiveDocument.Sections(1)
'Cell(4, 2).Range.InsertBefore (TextBox4.value)

    ' .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 2).Range.InsertAfter ("aaa")
  .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 3).Range.Delete
  .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 3).Range.InsertAfter (TxtFileName.Value)
 
  .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 2).Range.Delete
  .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 2).Range.InsertAfter (TxtSecrecy.Value)
  
  .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 4).Range.Delete
  .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 4).Range.InsertAfter (TxtRev.Value)
 
  .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 6).Range.Delete
  .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 6).Range.InsertAfter (TxtID.Value)
 
    '页尾的做法
'    .Footers(wdHeaderFooterPrimary).Range.Text = "Copyright  BYD Company Limited"
End With
AddHeader.Hide
End Sub

Private Sub CommandButton2_Click()
AddHeader.Hide
End Sub

你可能感兴趣的:(word)