如何在打开窗体时为 VBA 全局变量赋值,然后在单击按钮时更改其值?我知道如何做问题的第二部分。先感谢您。
更详细地,有一个计数器,其值必须在按钮按下过程之外确定。
Public counter As Long
Set (counter, 1) ' counter=1
...
Public Sub ButtonAdd_Click()
counter = counter+1
End Sub
如何在打开窗体时为 VBA 全局变量赋值,然后在单击按钮时更改其值?我知道如何做问题的第二部分。先感谢您。
更详细地,有一个计数器,其值必须在按钮按下过程之外确定。
Public counter As Long
Set (counter, 1) ' counter=1
...
Public Sub ButtonAdd_Click()
counter = counter+1
End Sub
Public Sub ButtonSave_Click()
Workbooks.Add
FiNum = 0
FiName = "C:\Users\svv71\Desktop\Test\Test" & FiNum & ".xlsx"
ActiveWorkbook.SaveAs Filename:=FiName
FiNum = FiNum + 1
ActiveWorkbook.Close
End Sub
'Кнопка добавить данные
Public Sub ButtonAdd_Click()
Dim i, n, k As Integer
n = Range("A2").CurrentRegion.Rows.Count + 1
k = n + 3
For i = 1 To 4
Cells(n, i + 1).Value = " & TextBox & i & "
Next
'Без цикла это работало так
'Cells(n, 1) = TextBox1
'Cells(n, 2) = TextBox2
'Cells(n, 3) = TextBox3
'Cells(n, 4) = TextBox4
End Sub
一般来说,问题是这样的:我编写了一个插入页眉和页脚的宏,并且它工作成功,但是在使用宏之前,您必须打开下拉菜单(插入页眉或插入页脚),这是唯一的方法宏将会起作用。如果刚刚创建了 .docx 文档,则在打开带有页眉和页脚的菜单之前,宏将不起作用。问题是,这个问题有没有解决方案,例如初始化页眉或页脚或加载页眉
Sub macr_horiz_A3()
Dim objTemplate As Template
Dim objBB As BuildingBlock
Dim folderPath As String
' Загружаем шаблон
folderPath = Environ("AppData") & "\Microsoft\Document Building Blocks\1049\16\Building Blocks.dotx"
Set objTemplate = Application.Templates(folderPath)
Set objBB = objTemplate.BuildingBlockEntries("a3horizontal")
' Сохраняем текущую позицию курсора
Dim currentPosition As Range
Set currentPosition = Selection.Range
' Меняем формат и колонтитул на текущей странице
currentPosition.Sections(1).Headers(wdHeaderFooterPrimary).Range.Delete
currentPosition.PageSetup.PaperSize = wdPaperA3
currentPosition.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = ""
objBB.Insert Where:=currentPosition.Sections(1).Headers(wdHeaderFooterPrimary).Range, RichText:=True
currentPosition.PageSetup.Orientation = wdOrientLandscape
End Sub