用与单元格值相对应的名称保存文件 [英] Save a file with a name that corresponds to a cell value
问题描述
背景:我正在使用一个宏来在不同的工作簿之间传输数据.其中一本工作簿是数据的传递渠道,并且不会改变.另一个工作簿是填充的空白表单,另存为特定名称,然后重新使用.
Background: I'm working with a macro that transfers data between different workbooks. One of the workbooks is a conduit for data and doesn't change. The other workbook is a blank form that is populated, saved as a specific name and then reused.
问题:要保存的工作簿需要使用导管工作簿中单元格的内容作为其名称.
Problem: The workbook being saved needs to use the contents of a cell in the conduit workbook for it's name.
I found a similar post here. The answer gives me a syntax error.
Sub TestTestTestTest()
'
' TestTestTestTest Macro
'
'
Dim name As String
name = Cells("Contents", A1)
ActiveWorkbook.SaveAs() Filename:=name**********
End Sub
加星号的行是语法错误的来源.
The starred line is the source of the syntax error.
推荐答案
您是否考虑过文件路径?或您从哪个工作簿中获取A1?
Have you considered the file path? or which workbook you are getting A1 from?
我认为Contents是一个工作表,而A1是文件名(对于以后查看此Contents的人来说,不是工作表)
I assume Contents is a sheet and A1 is the filename ( for future people looking at this Contents was not the sheet)
Dim name As String
name = range("A1").value
ActiveWorkbook.SaveAs Filename:=name
仅出于您的知识对可以使用的单元格进行操作
just for your knowledge to do the same with cells you can use
cells(1,1).value
单元格期望列/行的数值
Cells expects numerical values for column/row
要指向工作表,您可以使用
To point to a sheet you can use
sheets("sheet1").range("A1").value
sheets("sheet1").cells(1,1).value
您可以使用来缩短整个过程
You could shorten this whole thing by using
ActiveWorkbook.SaveAs Filename:=range("A1").value
这篇关于用与单元格值相对应的名称保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!