scorpio3st
New Member
- Joined
- Sep 7, 2021
- Messages
- 22
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
Sub SaveValues()
Dim SourceBook As Workbook, DestBook As Workbook, SourceSheet As Worksheet, DestSheet As Worksheet
Dim SavePath As String, i As Integer
Dim strFilename As String
Set rngRange = Worksheets("Sheet1").Range("M1")
Set SourceBook = ThisWorkbook
'*********************************************
'Edit next two lines as necessary
strFilename = rngRange.Value & Format(Now(), "dd.mm.yyyy")
SavePath = "C:\Users\akardos\Desktop\Privremeno/" & Sheets("Sheet1").Range("M1") & strFilename
Set SourceSheet = SourceBook.Sheets("Sheet1")
'*********************************************
Set DestBook = Workbooks.Add
Set DestSheet = DestBook.Worksheets.Add
Application.DisplayAlerts = False
For i = DestBook.Worksheets.Count To 2 Step -1
DestBook.Worksheets(i).Delete
Next i
Application.DisplayAlerts = True
SourceSheet.Cells.Copy
With DestSheet.Range("A1")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats 'Delete if you don't want formats copied
End With
DestSheet.Name = SourceSheet.Name
Application.DisplayAlerts = False 'Delete if you want overwrite warning
DestBook.SaveAs Filename:=SavePath
Application.DisplayAlerts = True 'Delete if you delete other line
SavePath = DestBook.FullName
DestBook.Close 'Delete if you want to leave copy open
MsgBox ("A copy has been saved to " & SavePath)
End Sub
This is Macro, but when run it saves document without xlsx or xls. Please can you help me to get extension.
Thanks.
Dim SourceBook As Workbook, DestBook As Workbook, SourceSheet As Worksheet, DestSheet As Worksheet
Dim SavePath As String, i As Integer
Dim strFilename As String
Set rngRange = Worksheets("Sheet1").Range("M1")
Set SourceBook = ThisWorkbook
'*********************************************
'Edit next two lines as necessary
strFilename = rngRange.Value & Format(Now(), "dd.mm.yyyy")
SavePath = "C:\Users\akardos\Desktop\Privremeno/" & Sheets("Sheet1").Range("M1") & strFilename
Set SourceSheet = SourceBook.Sheets("Sheet1")
'*********************************************
Set DestBook = Workbooks.Add
Set DestSheet = DestBook.Worksheets.Add
Application.DisplayAlerts = False
For i = DestBook.Worksheets.Count To 2 Step -1
DestBook.Worksheets(i).Delete
Next i
Application.DisplayAlerts = True
SourceSheet.Cells.Copy
With DestSheet.Range("A1")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats 'Delete if you don't want formats copied
End With
DestSheet.Name = SourceSheet.Name
Application.DisplayAlerts = False 'Delete if you want overwrite warning
DestBook.SaveAs Filename:=SavePath
Application.DisplayAlerts = True 'Delete if you delete other line
SavePath = DestBook.FullName
DestBook.Close 'Delete if you want to leave copy open
MsgBox ("A copy has been saved to " & SavePath)
End Sub
This is Macro, but when run it saves document without xlsx or xls. Please can you help me to get extension.
Thanks.