excel - 使用另一个工作簿中的文件名多次保存 excel 文件。
问题描述
我有一个小问题。我有 2 个文件。
我想在特定文件夹中多次保存“文件#1”。预期的文件名位于“文件#2”的 Sheet1 的 C 列中。我该怎么做?任何帮助将不胜感激。
:)
解决方案
这是从我用于类似的代码中提取的代码片段 - 它应该有所帮助:
Option Explicit
Sub Exportmacro()
Dim rCell As Range, rRng As Range 'define loop names
Dim NewCaseFile As Workbook 'give a name to new work book for duplicate sheet
Dim wks As Worksheet 'name of the copy of feedback
Dim sPath As String
sPath = MacScript("(path to desktop folder as string)")
'turn off screen
With Application
'.ScreenUpdating = False ‘only removed while testing
'.EnableEvents = False
'.Calculation = xlCalculationManual ‘disabled for the moment
End With
'Student numbers in cells A7:A160 WARNING SET TO 3 STUDENTS ONLY FOR TEST
Set rRng = Worksheets("studentlist").Range("A7:A9")
For Each rCell In rRng '<--| loop through "students" range
'now open new workbook
Set NewCaseFile = Workbooks.Add
'now save as xls with student number as filename Filename:=sPath & rCell.Value & ".xlsx"
ActiveWorkbook.SaveAs Filename:=rCell.Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
'now close duplicate file
ActiveWorkbook.Close False
Next rCell '<-- next student number
End With '<-- once all done
'turn screen back on
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
提供帮助您入门 - 您需要根据自己的需要对其进行编辑/更改。
推荐阅读
- pandas - AWS SageMaker 批量转换 CSV 错误:未引用字段中的“裸露”
- java - Java非常奇怪地处理大量数字
- r - 根据第 n 次出现的分隔符将一列分成两列
- python - 当 ANSI 转义序列字符在字符串中时,Python 字符串格式被忽略
- ruby-on-rails - 如何在我的 Rails 应用程序中执行操作之前确定延迟的原因?
- javascript - 针对过滤方法上的所有元素的事件侦听器
- unix - 将源脚本封装在 zsh 中
- c - C - Scanf 直接进入函数参数?
- unity3d - 我如何检测我的玩家是否正在触摸游戏对象?
- excel - Excel VBA - 以编程方式列出用户窗体上控件的可用事件过程