SaveAsCopy to folder with name from range
I want to use a code that saves a copy of the excel workbook i am using to a specific folder. This below is what I have but i don't seem to get any copies saved. The Value I have in "G4" is the name I would like the copy to be printed as. Does anyone have any ideas about what could be the problem? I am still having problems learning this VBA stuff=) Its hard for a new programmer. Sub SparatillFolder() Dim strFilename, strPathname, strDefpath As String On Error Resume Next ' If directory exist goto next line strFilename = sheets("Graf").Range("G4").Value 'New file name strDefpath = "\\C:"MYFOLDER" \dxakmh\Desktop\TestMiljö\Prognosverktyg\Sektionsfil\Gruppfiler\NyStruktur" 'Default path name If IsEmpty(strFilename) Then Exit Sub MkDir strDefpath strPathname = strFilename 'filename ActiveWorkbook.SaveCopyAs Filename:=strFilename & ".xlsm" End Sub Thanks in advance dear SO.
strDefpath should be strDefpath = "C:\dxakmh\Desktop\TestMiljö\Prognosverktyg\Sektionsfil\Gruppfiler\NyStruktur" also use .Text Example Sheets("Graf").Range("G4").Text Option Explicit Sub SparatillFolder() Dim strFilename As String Dim strDefpath As String 'New file name strFilename = ThisWorkbook.Sheets("Graf").Range("G4").Text strDefpath = "C:\dxakmh\Desktop\TestMiljö\Prognosverktyg\Sektionsfil\Gruppfiler\NyStruktur" If IsEmpty(strFilename) Then Exit Sub If Len(Dir(strDefpath, vbDirectory)) = 0 Then MkDir strDefpath ActiveWorkbook.SaveCopyAs Filename:=strDefpath & "\" & strFilename & ".xlsm" End Sub Range.Text Property (Excel) Returns or sets the text for the specified object. Read-only String.
Excel :How Do I Recover A Deleted Sheet In An Excel File?
Adding Comments To Name in Excel
Excel: Returning Value from third column if three match
Titus add-on won't allow me to save to PERSONAL.XLSB
change color of tab on sheets in a workbook based on date
Keep cell constant Excel
How to find cell containing string in entire worksheet
Use Excel VBA to reference add-in ribbon tool
Icon sets showing trend and number in same cell
VBA change cell value to run another macro
Save a number of excel worksheets as a PDF
How to edit column width of an Excel report which was created by an Access query?
i have a routine that saves specified sheets in a workbook to a pdf doc but if i make some of the sheets charts my routine falls over
Excel count distinct values in a date range by values
Excel, how to return a specific row from a data set
Count something based on another column