打开全部隐藏工作表
Sub 打开全部隐藏工作表()
Dim i As Integer
For i = 1 To Sheets.Count
Sheets(i).Visible = True
Next i
End Sub
根据A1单元文本隐藏/显示按钮
Private Sub CommandButton1_Click()
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Range("A1") = "显示按钮" Then
CommandButton1.Visible = 1
Else
CommandButton1.Visible = 0
End If
End Sub
当前单元返回按钮名称(控件按钮代码)
Private Sub CommandButton1_Click()
ActiveCell = CommandButton1.Caption
End Sub
当前单元内容返回到按钮名称(控件按钮代码)Private Sub CommandButton1_Click() CommandButton1.Caption = ActiveCell
End Sub
奇偶页分别打印
Sub 奇偶页分别打印()
Dim i%, Ps%
Ps = ExecuteExcel4Macro("GET.DOCUMENT(50)") '总页数  MsgBox "现在打印奇数页,按确定开始."
For i = 1 To Ps Step 2
ActiveSheet.PrintOut from:=i, To:=i
Next i
MsgBox "现在打印偶数页,按确定开始."
For i = 2 To Ps Step 2
ActiveSheet.PrintOut from:=i, To:=i
Next i
End Sub
自动打印多工作表第一页
Sub 自动打印多工作表第一页()
Dim sh As Integer
Dim x
Dim y
Dim sy
Dim syz
x = InputBox("请输入起始工作表名字:")
sy = InputBox("请输入结束工作表名字:")
y = Sheets(x).Index
syz = Sheets(sy).Index
For sh = y To syz
Sheets(sh).Select
Sheets(sh).PrintOut from:=1, To:=1
Next sh
End Sub
查A列文本循环插入分页符(模块)
Sub Macro1()
For i = 2 To Range("a65535").End(xlUp).Row If Cells(i, 1) = 1 Then
Worksheets("表2").HPageBreaks.Add Before:=Cells(i, 1)
End If
Next
End Sub
将A列最后数据行以上的所有B列图片大小调整为所在单元大小
Sub 将A列最后数据行以上的所有B列图片大小调整为所在单元大小()
Dim Pic As Picture, i&
i = [A65536].End(xlUp).Row
For Each Pic In Sheet1.Pictures
If Not Application.Intersect(Pic.TopLeftCell, Range("B1:B" & i)) Is Nothing Then            Pic.Top = Pic.TopLeftCell.Top
Pic.Left = Pic.TopLeftCell.Left
Pic.Height = Pic.TopLeftCell.Height
Pic.Width = Pic.TopLeftCell.Width
End If
Next
End Sub
返回光标所在行数
Sub 返回光标所在行数()
x = ActiveCell.Row
Range("A1") = x
End Sub
在A1返回当前选中单元格数量Sub 在A1返回当前选中单元格数量() [A1] = Selection.Count
End Sub
vb开始按钮代码
返回当前工作簿中工作表数量Sub 返回当前工作簿中工作表数量() t = Application.Sheets.Count MsgBox t
End Sub
返回光标选择区域的行数和列数Sub 返回光标选择区域的行数和列数() x = Selection.Rows.Count
y = Selection.Columns.Count Range("A1") = x
Range("A2") = y

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。