问题描述
如何创建一个宏(我将其命名为Test) 将:
How can I create a macro (I've named it Test) that will:
1.bring打开对话框(允许用户选择文件)
1.bring up the open dialogue box (to allow the user to choose a file)
2.保存文件,文件名由单元格A3中.xlsx格式的文本确定
2.save the file, with the file name determined by the text in cell A3 in .xlsx format
我有两段代码似乎单独工作,但不能一起工作:
I have two pieces code that seem to work individually, but not together:
Dim strFileName As String
strFileName = Application.GetOpenFilename
strFileName = Application.GetOpenFilename
如果strFileName =" False"然后退出Sub
If strFileName = "False" Then Exit Sub
MsgBox strFileName
MsgBox strFileName
ThisFile = Range(" ; A3")。值
ActiveWorkbook.SaveAs文件名:= ThisFile
ActiveWorkbook.SaveAs Filename:=ThisFile
感谢帮助!
推荐答案
只需很少的更改,这对我有用。我刚宣布你的最后一个变量。 (thisFile)
With very little change, this works for me. I just declared your last variable. (thisFile)
子测试()
Dim strFileName As String, thisFile As String
strFileName = Application.GetOpenFilename
如果strFileName =" False"然后退出Sub¥
MsgBox strFileName
thisFile =范围("A3")。值
ActiveWorkbook.SaveAs文件名:= thisFile
End Sub
Sub test()
Dim strFileName As String, thisFile As String
strFileName = Application.GetOpenFilename
If strFileName = "False" Then Exit Sub
MsgBox strFileName
thisFile = Range("A3").Value
ActiveWorkbook.SaveAs Filename:=thisFile
End Sub
这篇关于宏打开并保存为单元格中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!