excel


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.

Related Links

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

Categories

HOME
cordova
web-crawler
logistic-regression
mariadb
sublimelinter
opentsdb
soundcloud
rectangles
url-rewriting
codeception
pivot-table
slim
zk
pthreads
amazon-route53
esapi
react-boilerplate
nlog
stackdriver
xlwings
workspace
cookie-session
phylogeny
apl
angular-openlayers
ireport
radius
infowindow
sublimerepl
easymock
toml
hana-cloud-platform
android-runonuithread
templating
zlib
lpc
gear-vr
django-media
docker-registry
kubernetes-health-check
data-transfer
outlook-2016
local-variables
express-stormpath
cscore
decompression
kindle
dde
mailman
markov-models
kmip
android-selector
java-threads
rc4-cipher
grid-layout
oracle-streams
customdialog
zend-studio
stunnel
ooyala
mks-integrity
zurb-foundation-5
jedit
stompjs
command-line-tool
distinct-on
angular-ui-tree
android-context
agsxmpp
irssi
build-system
vin
jaggery-js
kindle-fire
accessdatasource
stop-words
teamsite
jsqlparser
syntactic-sugar
basic-msi
string-conversion
android-x86
usermode
styledtext
countries
texmacs
facebook-app-center
inference
mindmap
angularjs-e2e
aspnet-regiis.exe
dynamic-languages
jax-rpc
gwt-2.5
customer-support
objectiveflickr
nsinteger
git-add
glossary
function-overloading
visualtreehelper

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile