Saving an Excel workbook in a constant path with a file name of 2 fields

I am completely unfamiliar with Excel macros, I tried to find and compile code that matches my purpose, but without any luck. Hope someone is generous to help me.

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: Instead of naming the saved ck.xls file, generate the file name from the cells in table C5 and C8 with space in the middle.

+6
source share
2 answers

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 book using macros, use the code below

 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 the book without macros and not use the pop-up menu

 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 
+7
source

Well, at this time this was done with the help of a friend, and the code looks like this.

 Sub Saving() Dim part1 As String Dim part2 As String part1 = Range("C5").Value part2 = Range("C8").Value ActiveWorkbook.SaveAs Filename:= _ "C:\-docs\cmat\Desktop\pieteikumi\" & part1 & " " & part2 & ".xlsm", FileFormat:= _ xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False End Sub 

How to edit this part (FileFormat: = _ xlOpenXMLWorkbookMacroEnabled) so that it is saved in Excel 97-2013 Workbook, I tried several options without success. Thankyou

I seem to have found a solution, but my idea is wrong. By doing this FileFormat: = _ xlOpenXMLWorkbook, he throws up a pop-up saying: you cannot save this book as a file without macros included. So is this impossible?

+1
source

Source: https://habr.com/ru/post/952726/


All Articles