调用Excel宏批量处理文件
'1.用户可以任意选择文件夹进行遍历
'2.限定遍历时仅搜索EXCEL文件(你可以改变文件类型)
'这个程序要先在“引用”下选择"microsoft scripting runtime"库文件 Dim ArryFile() As String
Dim nFile As Integer
Sub Filelist()
Dim fso As New FileSystemObject
Dim fd As Folder
Dim strFilePath As String
Dim FolderSelect As FileDialog
Set FolderSelect = Application.FileDialog(msoFileDialogFolderPicker)
With FolderSelect
If .Show = -1 Then
strFilePath = .SelectedItems.Item(1) & "\"
End If
End With
Set fd = fso.GetFolder(strFilePath)
nFile = 0
searchFile fd
End Sub Private Function searchFile(ByVal fd As Folder)
Dim fl As File
Dim subfd As Folder
Dim i As Integer
On Error Resume Next i = fd.files.Count ReDim Preserve ArryFile(1 To nFile + i)
For Each fl In fd.files
If Right(fl.Name, 4) = "xlsx" Then '后缀是xls的用 If Right(fl.Name, 3) = "xls" Then
nFile = nFile + 1
ArryFile(nFile) = fl.Path
End If
Next
If fd.SubFolders.Count = 0 Then Exit Function
For Each subfd In fd.SubFolders
searchFile subfd
Next
End Function //主函数,运行时调用该函数
Sub ttt1() Dim xlname, myxl As Object, sh As Object Call Filelist 'Set myxl = CreateObject("Aplication.Excel") If nFile > 0 Then For Each xlname In ArryFile()
If xlname <> "" Then
//打开
Workbooks.Open Filename:=xlname
//调用Excel处理函数
Call Macro3
//保存,关闭
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
Next
End If Set myxl = Nothing
End Sub //Excel处理函数,该段替换成自己的处理过程
Sub Macro3()
'
' Macro3 Macro
'
' 快捷键: Ctrl+Shift+C
'
Range("V3:X3").Select
ActiveCell.FormulaR1C1 = "/"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "宋体"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("B5:J5").Select
ActiveCell.FormulaR1C1 = "R种植业 □林业 □畜牧业 □渔业 □其他 "
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Wingdings 2"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=2, Length:=3).Font
.Name = "宋体"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=5, Length:=2).Font
.Name = "Wingdings 2"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=7, Length:=3).Font
.Name = "宋体"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=10, Length:=2).Font
.Name = "Wingdings 2"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=12, Length:=4).Font
.Name = "宋体"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=16, Length:=4).Font
.Name = "Wingdings 2"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=20, Length:=3).Font
.Name = "宋体"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=23, Length:=4).Font
.Name = "Wingdings 2"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=27, Length:=3).Font
.Name = "宋体"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=30, Length:=1).Font
.Name = "Wingdings 2"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("O9:P35").Select
Selection.Copy
Range("E9:F35").Select
ActiveSheet.Paste
Application.CutCopyMode = False End Sub
调用Excel宏批量处理文件的更多相关文章
- bat文件调用cmd命令批量提取文件夹中的文件名(批量修改文件扩展名)
前言: 在平时的工作中,经常需要批量统计文件和数据,如果逐个统计的话太耗时,而且容易出错那么有没有什么快速的方法呢,这里给大家介绍一种简单高效的方法. 方法: 1.打开CMD命令: 按下 Ctrl+R ...
- Excel VBA批量修改文件夹下的文件名
今天,有同事提出想批量修改文件名,规则比较简单,在第五位后加“-”即可, 上网没找到相关工具,就自己做了个excel,用宏代码修改. 代码如下: Private Sub CommandButton1_ ...
- C#调用Excel宏
using System; using Excel = Microsoft.Office.Interop.Excel; namespace WindowsFormsApplication1 { /// ...
- C# 调用 Excel 宏的方法
调用方式是使用 Microsoft.Office.Interop.Excel.dll 组件来调用,该组件可以通过 Excel.exe 来生成,具体步骤如下: 第一步,进入 visual Studio ...
- C#调用Excel VBA宏
近日的一系列工作是做网站的营运维护,因此做了大量的支持工具.有Excel中写VBA的,也有直接C#做的工具.有时需要在C#中执行Excel VBA宏,甚至有时还需要在执行了VBA宏之后,获取返回值再进 ...
- C#调用Excel VBA宏[转载]
原文地址:https://www.cnblogs.com/heekui/archive/2008/03/30/1129355.html 近日的一系列工作是做网站的营运维护,因此做了大量的支持工具.有E ...
- 功能区按钮调用Excel、PowerPoint、Word中的VBA宏:RunMacro
功能区按钮调用Excel.PowerPoint.Word中的VBA宏:RunMacro 众所周知,Excel.PPT.Word文档或加载宏文件中可以写很多过程和函数,调试的过程中当然可以按F8或F5直 ...
- 使用vbs调用excel中的宏
使用vbs打开excel文件,并且传递参数调用excel中的macro,自动化完成excel文件的制作. Set oExcel = createobject("Excel.Applicati ...
- Excel技巧--批量生成指定名称的文件夹
当我要按excel表当中的名字来批量生成文件夹时,手动一个个制作很麻烦(特别是成百上千个时).于是我们可以这么做: 1.在名字右侧建立公式:"MD "&A2. 2.将公式拖 ...
随机推荐
- ajax调用.net API项目跨域问题解决
ajax调用.net API项目,经常提示跨域问题.添加如下节点代码解决:httpProtocol <system.webServer> <handlers> <remo ...
- MySQL(进阶部分)
视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用. SELECT * FROM ( SEL ...
- 加载配置文件-properties
Properties jdbcProp = new Properties(); jdbcProp.load(getClass().getResourceAsStream("/jdbc.pro ...
- SQLserver登陆报错
https://blog.csdn.net/captain618/article/details/52331372 今天也不知道sql server抽了什么风,无论是windows登录还是sa登录,登 ...
- 性能测试进阶指南——基础篇之磁盘IO
本文旨在帮助测试人员对性能测试常用指标做一个简单的讲解,主要包括CPU.内存.磁盘和网络带宽等系统资源,本文仅仅局限于Linux系统,Windows Server系统暂不做考虑. 使用iostat分析 ...
- maven repository pom
场景: 如果maven setting.xml 中没指定国内的镜像 可以通过在项目中的pom中指定 指定repository : <properties> <java.version ...
- Tensorflow卷积神经网络[转]
Tensorflow卷积神经网络 卷积神经网络(Convolutional Neural Network, CNN)是一种前馈神经网络, 在计算机视觉等领域被广泛应用. 本文将简单介绍其原理并分析Te ...
- BASH_SOURCE
在C/C++中,__FUNCTION__常量记录当前函数的名称.有时候,在日志输出的时候包含这些信息是非常有用的.而在Bash中,同样有这样一个常量FUNCNAME,但是有一点区别是,它是一个数组而非 ...
- 程序配置的原则和实践以及 Spring Boot 支持方式
原则 软件需要在不同的环境中部署,代码是保持不变的,但是不同的运行环境存在差异,所以需要使用配置适应不同的环境.比如: 数据库,Redis,以及其他 后端服务 的配置: 第三方服务的证书,如 oAut ...
- Day02 - Ruby比一比:Module模块与Class类别
前情提要 在第一天里,我很激昂地用Ruby的类别.物件.方法,写了宣言! class TingIsIronman def initialize @message =“I'm going to writ ...