zoukankan      html  css  js  c++  java
  • EXCLE使用宏生成目录

    宏代码:

    Sub mu()
    Dim i As Integer
    Dim ShtCount As Integer
    Dim SelectionCell As Range
    
    ShtCount = Worksheets.Count
    If ShtCount = 0 Or ShtCount = 1 Then Exit Sub
    Application.ScreenUpdating = False
    For i = 1 To ShtCount
    If Sheets(i).Name = "目录" Then
    Sheets("目录").Move Before:=Sheets(1)
    End If
    Next i
    If Sheets(1).Name <> "目录" Then
    ShtCount = ShtCount + 1
    Sheets(1).Select
    Sheets.Add
    Sheets(1).Name = "目录"
    End If
    Sheets("目录").Select
    Columns("B:B").Delete Shift:=xlToLeft
    Application.StatusBar = "正在生成目录…………请等待!"
    For i = 2 To ShtCount
    ActiveSheet.Hyperlinks.Add Anchor:=Worksheets("目录").Cells(i, 2), Address:="", SubAddress:= _
    "'" & Sheets(i).Name & "'!R1C1", TextToDisplay:="'" & Sheets(i).Name
    Next
    Sheets("目录").Select
    Columns("B:B").AutoFit
    Cells(1, 2) = "目录"
    Set SelectionCell = Worksheets("目录").Range("B1")
    With SelectionCell
    .HorizontalAlignment = xlDistributed
    .VerticalAlignment = xlCenter
    .AddIndent = True
    .Font.Bold = True
    .Interior.ColorIndex = 34
    End With
    Application.StatusBar = False
    Application.ScreenUpdating = True
    Tuichu:
    End Sub
    

      上面是VB代码,具体操作步骤如下:

    新建test.xlsx----开发工具------宏-----创建宏

    点击创建后如下图:

    接着再界面上插入一个按钮

    然后点击按钮,右键---指定宏,出现下图

  • 相关阅读:
    MySQL(一)
    HTML基础
    python函数基础
    常用的模块
    面向对象进阶
    定制自己的数据类型
    Shell篇之AWK
    MATLAB如何实现傅里叶变换FFT?有何物理意义?
    傅里叶分析
    2018年度关键词
  • 原文地址:https://www.cnblogs.com/OliverQin/p/5807904.html
Copyright © 2011-2022 走看看