如何在两种形式之间共享变量?

时间:2019-06-21 16:37:11

标签: forms hyperlink

Private Sub NextButton_Click()


  Set objword = CreateObject("Word.Application")
  objword.Visible = True
Set objdoc = objword.Documents.Add
objword.Selection.PageSetup.Orientation = wdOrientLandscape
  Set objrange = objdoc.Range

'Create Title Table
  objdoc.Tables.Add objrange, 2, 1
  Set TitleTable = objdoc.Tables(1)
  objdoc.Paragraphs.Add
  TitleTable.Borders.Enable = True
  Set myrange = objdoc.Content
myrange.Collapse Direction:=wdCollapseEnd

'Create table for info
objdoc.Tables.Add Range:=myrange, NumRows:=4, _
 NumColumns:=2
  Set InfoTable = objdoc.Tables(2)
  objdoc.Paragraphs.Add
  InfoTable.Borders.Enable = True
Set myrange = objdoc.Content
myrange.Collapse Direction:=wdCollapseEnd


objdoc.Tables.Add Range:=myrange, NumRows:=6, _
 NumColumns:=10
 Set objtable2 = objdoc.Tables(3)
 'objTable.Borders.Enable = True
     objtable2.Borders.Enable = True

'objtable2.Tables.Cell(1, 1).Text = "abc"
'ActiveDocument.Tables(1).Cell(1, 1).Text = "abc"
With TitleTable
.Cell(1, 1).Range.InsertAfter "Installation Qualification for" & " " & EquipType.Value & " " & ModelName.Value & " " & SerialNum.Value
.Cell(2, 1).Range.InsertAfter DocName.Value


End With

With InfoTable
.Cell(1, 1).Range.InsertAfter "Company"
.Cell(2, 1).Range.InsertAfter "Equipment Type"
.Cell(3, 1).Range.InsertAfter "Location"
.Cell(4, 1).Range.InsertAfter "Approver(s)"

.Cell(1, 2).Range.InsertAfter CompName.Value
.Cell(2, 2).Range.InsertAfter EquipType.Value
.Cell(3, 2).Range.InsertAfter RoomNum.Value
.Cell(4, 2).Range.InsertAfter ApproverNames.Value
End With
  AddEquipForm.Show

end sub

这是一种格式(字)下的代码,用于创建表并在其中填充信息。然后,我想继续使用第二种形式,并要在同一文档上工作,但是变量不会被继承。我确实尝试在模块中声明为public,但这没有用。

第二种形式的代码:

Private Sub AddMore_Click()

Set myrange = objdoc.Content
myrange.Collapse Direction:=wdCollapseEnd


With myrange
    .Collapse Direction:=wdCollapseEnd
    .InsertBreak Type:=wdPageBreak
End With
End Sub

如何使两种形式共享变量?

0 个答案:

没有答案