VBA to save .xls in same folder as original document

Samahonka

New Member
Joined
Feb 17, 2019
Messages
2
Hi all,

I'm trying to use a stadard form called "Master Cleandeskform.xls", and I would like to save it in the same folder as the original document, under differend name.
Cell F3 contains the date, which is used to complete the file name.
Example: "Cleandeskform 17-02-2019.xls"

Everything is working fine, except the file is stored in the folder "My documents", which isn't the folder the original document is stored in.

This is te vba code I've used:

Sub SaveThis****()

Dim FName As String
Dim FDate As String

FName = Cleandeskform "
FDate = Sheets("Sheet1").Range("F3").Text
ThisWorkbook.SaveAs filename:=Fname & FDate

End Sub
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

wist

Board Regular
Joined
Nov 8, 2012
Messages
79
Hi, try this

Code:
Sub SaveThis()

Dim FName As String
Dim FDate As String
Dim wbpath As String

wbpath = Workbooks("Master Cleandeskform.xls").Path
FName = "Cleandeskform "
FDate = Sheets("Sheet1").Range("F3").Text
ThisWorkbook.SaveAs Filename:=wbpath & "\" & FName & FDate

End Sub
 
Last edited:

Samahonka

New Member
Joined
Feb 17, 2019
Messages
2
Thanks Wist!

I'll try that code also.

I've been coding myself also, and I came up with my own solution which did the trick:

Sub SaveThis()

Dim FDate As String

FDate = Sheets("Sheet1").Range("F4").Text
SaveAsName = ThisWorkbook.Path
ThisWorkbook.SaveAs SaveAsName & "" & "Cleandeskform " & FDate

End Sub



Hi, try this

Code:
Sub SaveThis()

Dim FName As String
Dim FDate As String
Dim wbpath As String

wbpath = Workbooks("Master Cleandeskform.xls").Path
FName = "Cleandeskform "
FDate = Sheets("Sheet1").Range("F3").Text
ThisWorkbook.SaveAs Filename:=wbpath & "\" & FName & FDate

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,108,707
Messages
5,524,424
Members
409,577
Latest member
Dwg

This Week's Hot Topics

Top