我的个人宏文件

news/2025/1/11 22:45:50/

 Public N As Integer
Sub 当前表总行数() 'ActiveSheet.UsedRange.Rows.Count
' 当前表总行数 Macro
' 宏由录制,时间: 2008-8-6
    ActiveSheet.Select
    For i = 65536 To 1 Step -1
    If Cells(i, 1) <> "" Then
       N = i
       'h = MsgBox(i, vbOKOnly, "行数")
       Exit For '退出FOR循环
       'End 退出程序
    End If
    Next i
End Sub
Sub 向下复制选定内容()
' Macro2 向下复制选定内容
' 宏由录制,时间: 2008-8-16
    Application.Run "PERSONAL.XLS!当前表总行数"
    'Dim N As Long
    'N = ActiveSheet.UsedRange.Rows.Count
    Selection.copy
    For i = 1 To N - Selection.Row
       If IsEmpty(ActiveCell.Offset(1, 0)) Then
          ActiveCell.Offset(1, 0).Select
          ActiveSheet.Paste
       Else
          ActiveCell.Offset(1, 0).Select
       End If
    Next i
End Sub
Sub 条件复制()
    Application.Run "PERSONAL.XLS!当前表总行数"
    Selection.copy
    For i = 1 To N - Selection.Row
       If (ActiveCell.Offset(1, 0).Interior.ColorIndex = xlNone) And (ActiveCell.Offset(1, 0).Font.ColorIndex = -4105) Then
          ActiveCell.Offset(1, 0).Select
          ActiveSheet.Paste
       Else
          ActiveCell.Offset(1, 0).Select
       End If
    Next i
End Sub
Sub 选择性数值粘贴()
' 选择性数值粘贴 Macro
' 宏由 蒋芳 录制,时间: 2008-8-25
    Cells.Select
    Selection.copy
    Sheets.Add
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub
Sub 复制粘贴()
    Cells.Select
    Selection.copy
    Set NewSheet = Sheets.Add(Type:=xlWorksheet)
    NewSheet.Range("A1").Select
    NewSheet.Paste
    'Cells.Select
    'Selection.copy
    'Sheets.Add
    'ActiveSheet.Paste
End Sub
Sub 提取工作簿()
Dim FilesToOpen
Dim x As Integer
On Error GoTo ErrHandler              '假如有错,那么跳至ErrHandler 处
ChDrive "f"  'ChDrive Left(ThisWorkbook.FullName, 1)也可  '打开时可直接指向文件所在路径
ChDir ThisWorkbook.Path
  Application.ScreenUpdating = False
      FilesToOpen = Application.GetOpenFilename _
        (FileFilter:="Microsoft Excel Files (*.xls), *.xls", _
        MultiSelect:=True, Title:="Files to Merge")      '支持复选
  If TypeName(FilesToOpen) <> "Boolean" Then
    Application.DisplayAlerts = False
    For x = 1 To UBound(FilesToOpen)              '如果不想打开自己
      t$ = t$ & "[" & FilesToOpen(x)
    Next
      If InStr(t$, ThisWorkbook.FullName) Then MsgBox "不可以选择本文件! ", 16, "提示:": Exit Sub
            x = 1
          While x <= UBound(FilesToOpen)
            Set wk = Application.Workbooks.Open(FilesToOpen(x))
            wk.Sheets(1).Cells.copy ThisWorkbook.Sheets(x).Cells
            x = x + 1
            wk.Close False
          Wend
  Else
    MsgBox "No Files were selected"
  End If
    Application.ScreenUpdating = True
  End              '如果一切正常,那么到这里可以放置全部结束
ErrHandler:
    MsgBox Err.Description  '显示错误类型
End Sub
Sub 生成区域报表()
' Macro1 Macro
' 宏由 Soul 录制,时间: 2008-9-10
Dim nUP As Long
On Error Resume Next '如果出现错误,继续运行下面的代码
zzml = "选择要制作目录的文件夹" '以下代码弹出一个选择文件夹对话框
Set mlzz = CreateObject("Shell.Application").BrowseForFolder(0, zzml, &H1)
lj = mlzz.Self.Path '将选中文件夹的路径传递给变量lj
nSheetname = ActiveSheet.Name
nYCB = 0 '记录隐藏表个数
For i = 1 To Worksheets.Count
    If Sheets(i).Visible = False Then nYCB = nYCB + 1
Next i
nUP = 7
   For i = 1 To ActiveSheet.UsedRange.Rows.Count
       If (Range("A" & i) <> "") And (Right(Range("A" & i), 2) = "合计") Then
           Sheets(nSheetname).copy Before:=Sheets(1)
           Range("A" & i + 1 & " : IV" & ActiveSheet.UsedRange.Rows.Count).Delete
           Sheets(nYCB + 1).Name = Left(Range("A" & i), Len(Range("A" & i)) - 2)
           Bmstring = Left(Range("A" & i), Len(Range("A" & i)) - 2)
           If Sheets(nYCB + 1).Name <> "吕宾区" Then Range("A" & 6 & " : IV" & nUP).Delete
           Sheets(nYCB + 1).Move
           ActiveWorkbook.SaveAs FileName:=lj & "/" & Bmstring, FileFormat:=xlNormal, _
            Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
            ActiveWindow.Close
            nUP = i
       End If
   Next i
End Sub
Sub 批量单个保存电子表()
    '将同一个文件里的表,独立保存为一个文件
Application.ScreenUpdating = False   '隐藏宏的执行过程
    zzml = "选择要制作目录的文件夹" '以下代码弹出一个选择文件夹对话框
    Set mlzz = CreateObject("Shell.Application").BrowseForFolder(0, zzml, &H1)
    lj = mlzz.Self.Path '将选中文件夹的路径传递给变量lj
   
Start:
   
    N = CVar(InputBox("从第几个表开始复制?", "批量单个保存电子表", 1))
    On Error Resume Next
    If N > Worksheets.Count Then
        MsgBox "请输入少于" & Worksheets.Count & "自然数", vbOKOnly
        GoTo Start
    End If
   
    For i = N To Worksheets.Count
        N_name = Sheets(i).Name         '提取表名作为文件名
        Sheets(i).copy
                                        '指定目标存放文件夹         文件名
        ActiveWorkbook.SaveAs FileName:=lj & "/" & N_name & ".xls", FileFormat:=xlNormal, _
            Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
            CreateBackup:=False
        ActiveWindow.Close
    Next
Application.ScreenUpdating = True

End Sub
Sub 宋体10号()
' Macro1 宋体10号
' 宏由录制,时间: 2008-8-18
    ActiveSheet.Select    'Sheets(ActiveSheet.Name).Select
    With Selection.Font
        .Name = "宋体"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
End Sub
Sub 日期格式()
' Macro8 日期格式(某月某日)
' 宏由 Soul 录制,时间: 2008-8-18
  'ActiveCell.NumberFormatLocal = "m""月""d""日"";@"  单前选中的第一个单元格
  Selection.NumberFormatLocal = "m""月""d""日"";@" '单前选中的所有单元格
End Sub
'移除VBA编码保护调用
'1>一段极好的VBA保护密码破解程序测试WIN98+OFFICE97破解率100%
'2>用以下代码对VBA加密保护后用offkey 6.5-7.0及Advanced VBA pASSWORD Recovery专业版均无法破解出保护程式码的密码
Sub MoveProtect()
  Dim FileName As String
  FileName = Application.GetOpenFilename("Excel文件(*.xls & *.xla),*.xls;*.xla", , "VBA破解")
  If FileName = CStr(False) Then
     Exit Sub
  Else
     VBAPassword FileName, False
  End If
End Sub
'设置VBA编码保护调用
Sub SetProtect()
  Dim FileName As String
  FileName = Application.GetOpenFilename("Excel文件(*.xls & *.xla),*.xls;*.xla", , "VBA破解")
  If FileName = CStr(False) Then
     Exit Sub
  Else
     VBAPassword FileName, True
  End If
End Sub
Private Function VBAPassword(FileName As String, Optional Protect As Boolean = False) '设置与移除VBA编码保护
    If Dir(FileName) = "" Then
       Exit Function
    Else
       FileCopy FileName, FileName & ".bak"
    End If
    Dim GetData As String * 5
    Open FileName For Binary As #1
    Dim CMGs As Long
    Dim DPBo As Long
    For i = 1 To LOF(1)
        Get #1, i, GetData
        If GetData = "CMG=""" Then CMGs = i
        If GetData = "[Host" Then DPBo = i - 2: Exit For
    Next
    
    If CMGs = 0 Then
       MsgBox "请先对VBA编码设置一个保护密码...", 32, "提示"
       Exit Function
    End If
    
    If Protect = False Then
       Dim St As String * 2
       Dim s20 As String * 1
       
       '取得一个0D0A十六进制字串
       Get #1, CMGs - 2, St
    
       '取得一个20十六制字串
       Get #1, DPBo + 16, s20
    
       '替换加密部份机码
       For i = CMGs To DPBo Step 2
           Put #1, i, St
       Next
       
       '加入不配对符号
       If (DPBo - CMGs) Mod 2 <> 0 Then
          Put #1, DPBo + 1, s20
       End If
       MsgBox "文件解密成功......", 32, "提示"
    Else
       Dim MMs As String * 5
       MMs = "DPB="""
       Put #1, CMGs, MMs
       MsgBox "对文件特殊加密成功......", 32, "提示"
    End If
    Close #1
End Function
Sub 生成部门利润表()
On Error Resume Next '如果出现错误,继续运行下面的代码
zzml = "选择要制作目录的文件夹" '以下代码弹出一个选择文件夹对话框
Set mlzz = CreateObject("Shell.Application").BrowseForFolder(0, zzml, &H1)
lj = mlzz.Self.Path '将选中文件夹的路径传递给变量lj
ActiveWorkbook.SaveCopyAs lj & "/" & ActiveWorkbook.Name
BMcount = 0
littlesection = Range("ID!B2").Value
RowCount = [ID!C65536].End(xlUp).Row
For i = 2 To RowCount
    '建立文件夹
    If Range("ID!A" & i).Value <> "" Then
        packnamesting = Range("ID!A" & i).Value
        MkDir lj & "/" & packnamesting
        largesection = Range("ID!A" & i).Value
        littlesection = Range("ID!B" & i).Value
    End If
    '复制利润表
    If Range("ID!D" & i).Value <> "" Then
        Sheets("aa").copy Before:=Sheets(1)
        Sheets(1).Name = Range("ID!C" & i).Value
        BMcount = BMcount + 1
    End If
    '保存为独立文件
    If Range("ID!B" & i + 1).Value <> "" Or i = RowCount Then
        '命名及保存文件
            ActiveWorkbook.SaveCopyAs lj & "/" & packnamesting & "/" & littlesection & ".xls"
            Workbooks.Open FileName:=lj & "/" & packnamesting & "/" & littlesection & ".xls"
        '删除多余的工作表
            Application.DisplayAlerts = False
            For l = BMcount + 1 To Sheets.Count
                Sheets(Sheets.Count).Delete
            Next
            ActiveWorkbook.Save
            ActiveWindow.Close
            For N = 1 To BMcount
                Sheets(1).Delete
            Next
            Application.DisplayAlerts = True
            littlesection = Range("ID!B" & i + 1).Value
            BMcount = 0
    End If
Next
End Sub

 


http://www.ppmy.cn/news/632155.html

相关文章

【为宏正名】99%人都不知道的“##“里用法

【说在前面的话】 有人说C语言中最臭名昭著的两兄弟就是指针和宏了。对于前者&#xff0c;很多有经验的老鸟会告诉你&#xff1a;用好了指针你就掌握了C语言的内功心法——如同原力一样&#xff0c;无论是追随光明还是堕入黑暗都离不开它。宏就没这么幸运了&#xff0c;不光年年…

linux gcc 宏定义 __GNUC__ __GNUC_MINOR__ 版本区分

今天在看Linux系统编程这本书的代码的时候看到了__GNUC__&#xff0c;不太清楚这个宏所以去查了一下&#xff0c;以此记录。GNU C预定义了一系列的宏&#xff0c;这些宏都是以双下划线开始的&#xff0c;这里只讲一下__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__&#xff0c;…

灰色的果实

灰色的果实 问题描述 树为灰色果实之树&#xff0c;不定时会长出灰色果实。贸然接近果实只会使得自己受其迷惑最后神经错乱而 浑浑噩噩不得终日&#xff0c;与死人无异。你的目标是成功到达树的顶端&#xff0c;砍下灰色果实的灵脉。 为了能够免除灰色果实的影响&#xff0…

告诉你什么是 Java 宏变量,别再疑惑不解了

小编第一次被问到这个概念时&#xff0c;确实是有点懵。入行没多久&#xff0c;莫怪莫怪&#xff01;后来翻阅一些资料和博客&#xff0c;才豁然开朗。 小编认为Java中其实没有关于宏的定义&#xff0c;《Thinking in Java》中我也没有找到相关的介绍。这个概念应该是从C语言中…

恶魔果实

组合题&#xff08;牛客&#xff09;: 恶魔果实. 题目描述 牛牛得到了一堆神奇的恶魔果实&#xff0c;每个恶魔果实都给了牛牛一个改变数字的能力&#xff0c;可以把数字a变成数字b&#xff0c;现在牛牛有一个数字x&#xff0c;他想知道吃完这n个恶魔果实后&#xff0c;他可以…

gcc宏展开

要把源代码中的宏展开&#xff0c;其实只要使用gcc进行预处理即可。 gcc -E source.c >out.txt -E表示只进行预处理&#xff0c;不进行编译。 预处理时会把注释当成空格处理掉&#xff0c;如果想保留其中的注释&#xff0c;可以加上-C选项&#xff0c;即&#xff1a; gc…

将一个宏被另一个宏使用

带参数的宏定义的一般形式如下&#xff1a; #define <宏名>&#xff08;<参数表>&#xff09; <宏体> 一.如下图 我想要计算一个三角形的面积 我要定义两个宏&#xff1a;一个用来表示&#xff1a;s1/2*(abc) 一个用来表示&#xff1a; (s-a)(s-b)*(s-c) …

NLP创业破局,如何摘取更高处的果实

点击蓝字 关注我们 AI TIME欢迎每一位AI爱好者的加入&#xff01; 2022年&#xff0c;云从科技、商汤科技先后登陆资本市场&#xff0c;计算机视觉四小龙中的旷视科技、依图科技也在摩拳擦掌。反观NLP领域&#xff0c;相关企业的发展速度、融资规模、上市进程仿佛都要略逊一筹&…