将Excel工作簿保存到2个字段的文件名的常量路径 [英] Saving Excel workbook to constant path with filename from 2 fields
本文介绍了将Excel工作簿保存到2个字段的文件名的常量路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Sub save()
ActiveWorkbook.SaveAS文件名:= C:\-docs\cmat\Desktop\New folder\ck.xls,FileFormat:= _
xlNormal,Password:=,WriteResPassword:=,ReadOnlyRecommended:= False _
,CreateBackup:= False
End Sub
如何编辑:
而不是命名保存的文件ck.xls,从工作表单元格C5和C8生成文件名,中间有一个空格。
解决方案
尝试
Sub save()
ActiveWorkbook.SaveAS文件名:=C:\-docs\cmat\Desktop\New folder\&范围(C5)。 chr(32)& Range(C8)。Text&。xls,FileFormat:= _
xlNormal,Password:=,WriteResPassword:=,ReadOnlyRecommended:= False _
,CreateBackup:= False
End Sub
如果要使用宏保存工作簿,请使用以下代码
Sub save()
ActiveWorkbook.SaveAs文件名:=C:\Users\ Environ $(username)& _
\Desktop\&范围(C5)。 Chr(32)&范围(C8)。 .xlsm,FileFormat:= _
xlOpenXMLWorkbookMacroEnabled,Password:= vbNullString,WriteResPassword:= vbNullString,_
ReadOnlyRecommended:= False,CreateBackup:= False
End Sub
如果你想保存没有宏的工作簿,没有弹出窗口使用这个
Sub save()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs文件名:=C:\Users\& Environ $(username)& _
\Desktop\&范围(C5)。 Chr(32)&范围(C8)。 .xls,_
FileFormat:= xlOpenXMLWorkbook,CreateBackup:= False
Application.DisplayAlerts = True
End Sub
I am absolutely new to Excel macros, I tried to search and put together a code to fit my purpose, but with no luck. I hope someone is generous enough to help me out.
Sub save()
ActiveWorkbook.SaveAS Filename:="C:\-docs\cmat\Desktop\New folder\ck.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub
How to edit this to: Instead of naming the saved file ck.xls, generate the filename from the worksheet cells C5 and C8, with a space in the middle.
解决方案
try
Sub save()
ActiveWorkbook.SaveAS Filename:="C:\-docs\cmat\Desktop\New folder\" & Range("C5").Text & chr(32) & Range("C8").Text &".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub
If you want to save the workbook with the macros use the below code
Sub save()
ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("username") & _
"\Desktop\" & Range("C5").Text & Chr(32) & Range("C8").Text & ".xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, Password:=vbNullString, WriteResPassword:=vbNullString, _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub
if you want to save workbook with no macros and no pop-up use this
Sub save()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("username") & _
"\Desktop\" & Range("C5").Text & Chr(32) & Range("C8").Text & ".xls", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
End Sub
这篇关于将Excel工作簿保存到2个字段的文件名的常量路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文