vba SaveAsXLSM

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have a code that allows me to create a new excel document from an existing one, where it closes the existing document and opens up the new created document.

Here it is and works wonderful in this way:


VBA Code:
Dim strName As String
        
    strName = ThisWorkbook.Path & "\" & Format(Date, "DDMMMYYYY ") & Sheet1.Name & " " & ".xlsm"
    
    ActiveSheet.Copy
    ThisWorkbook.SaveAs FileName:=strName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    ActiveWorkbook.Close savechanges:=False


My question is how do I modify this code to create an existing document, which does not close the existing document but rather creates a new document unopened?

I'm not sure how to modify this code.

Please let me know if you know how to do this.

Thank you,
pinaceous
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
How about
VBA Code:
Dim strName As String
        
    strName = ThisWorkbook.Path & "\" & Format(Date, "DDMMMYYYY ") & Sheet1.Name & " " & ".xlsm"
    ThisWorkbook.SaveCopyAs strName
 
Upvote 0
Hi Fluff,

I appreciate your post & your code!

I see says the blind man.

Thank you!
pinaceous
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Fluff,

If I have the following:

VBA Code:
Dim strName As String
    
    strName = ThisWorkbook.Path & "\" & "FILES NAME FOR 2020 " & ".xlsm"

    ThisWorkbook.SaveCopyAs strName

Is there any way I can have the code reference the "TITLE" from inside the workbook?

For example, if I have on Worksheets(1) Cell "A1" the text of
"FILES NAME FOR 2020 "

Could I reference that in the code?

Something like this:

Code:
 strName = ThisWorkbook.Path & "\" & "(Worksheet(1) Cell "A1")" & ".xlsm"

Please let me know.

Thank you!
pinaceous
 
Upvote 0
How about
VBA Code:
strName = ThisWorkbook.Path & "\" & Worksheets(1).Range("A1").value  & ".xlsm"
 
Upvote 0
Nice Fluff! Cannot wait to test it! Thanks again!
 
Upvote 0
Good Day,

In using this code above from post #6, is there anyway that I can write an error message for this code?

For example, when I use this code depending upon the speed of the computer; Excel sometimes accompanies this code with an extra macro-free workbook called:

Book1.xlsx

Is there anyway that I can prevent this from happening through FSO?

This is what I have up until now that I'm writing as a separately run code, but not sure:

VBA Code:
Sub VBA_Delete_Workbook_Excel_Using_FSO()
'Delete Workbook in Excel VBA using DeleteFile method of FSO
'?Remove MsgBox'sx2

    'Variable declaration
    Dim FSO
    Dim sWorkbookName As String
   
    'File Name to delete:
    sWorkbookName = "Book1.xlsx"
           
    'Set Object for file system object
    Set FSO = CreateObject("Scripting.FileSystemObject")
   
    'Before deleting check file exists or not
    If FSO.FileExists(sWorkbookName) Then
   
        'If file exists, It will delete the file from source location
        FSO.DeleteFile sWorkbookName, True
        MsgBox "Workbook has deleted successfully.", vbInformation
    Else
   
        'If file does not exists, It will display following message
        MsgBox "Specified Workbook was not found", vbInformation, "Not Found!"
    End If
      
End Sub


Please let me know & thank you so much!

pinaceous
 
Upvote 0
As you already have a thread running for this problem, you need to keep to it. Thanks
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,939
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top