It is not saving correctly, in need of help to correct it

Mfana

New Member
Joined
Mar 5, 2018
Messages
8
Sub SavNewInvWithNewName()
Dim NewFN As Variant


' Copy New Invoice to a new workbook
ActiveSheet.Copy
NewFN = "C:\Documents\HOUSING" & Range("I7").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlXMLSpreadsheet
ActiveWorkbook.Close
NextInvoice
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
.
Code:
Option Explicit


Sub CreateNewDataBase()
Dim MyFolder As String
Dim fname As String, ext As String
Dim TempFolder As String


   MkDir "C:\Users\My\Documents\HOUSING\"           '<-- Edit path as required
   MyFolder = "C:\Users\My\Documents\HOUSING\"       '<-- Edit path as required
   If MyFolder = "" Then Exit Sub
   fname = Range("I7").Value & ".xlsx"


    ActiveSheet.Copy
    ActiveWorkbook.SaveAs Filename:=MyFolder & fname, _
         CreateBackup:=False
    ActiveWorkbook.Close False
    
    On Error Resume Next
    On Error GoTo 0
MsgBox "Done!"
End Sub

Edit paths as required for your system.
 
Upvote 0
Thanks for your contribution, however, the case in point is access denied having configured correctly or maybe one is missing out. Please help.

Sub CreateNewDataBase()
Dim MyFolder As String
Dim fname As String, ext As String
Dim TempFolder As String




MkDir "C:\Users\User\Documents\HOUSING"
MyFolder = "C:\Users\User\Documents\HOUSING"
If MyFolder = "" Then Exit Sub
fname = Range("I7").Value & ".xlsx"




ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=MyFolder & fname, _
CreateBackup:=False
ActiveWorkbook.Close False

On Error Resume Next
On Error GoTo 0
MsgBox "Done!"
End Sub
 
Upvote 0
.
Code:
MkDir "C:\Users\My\Documents\HOUSING\"          [COLOR=#ff0000][B] '<-- Edit path as required[/B][/COLOR]
   MyFolder = "C:\Users\My\Documents\HOUSING\"       [COLOR=#ff0000][B]'<-- Edit path as required[/B][/COLOR]


Change the path to fit your computer as I indicated in my original post.
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,549
Members
449,170
Latest member
Gkiller

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