Save As macro not saving to current directory

josullivan601632

New Member
Joined
Aug 23, 2020
Messages
23
Office Version
  1. 2007
Platform
  1. Windows
Hi I have a macro (using a button) for save as, (using the value of a cell + date), that works great, however all of a sudden it has stopped saving in the current directory/folder and is going in my local disk and I don't know how to fix it :(

This is what I have:

Sub Macro1()
'
' Macro1 Macro
'
Dim fname As String
fname = Range("B2") & Format(Now(), " DD.MM.YY") & ".xlsm"
MsgBox fname
ActiveWorkbook.SaveAs Filename:=fname
End Sub

I know I could specify the filepath but don't know how to write that code AND have " Range("B2") & Format(Now(), " DD.MM.YY") & ".xlsm "

Any help would be greatly appreciated!
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,939
Office Version
  1. 365
Platform
  1. Windows
You are missing the " in front of P:\...

It should be:
fname = "P:\Buyers Files\Buyers Worksheets\" & Range("B2") & Format(Now(), " DD.MM.YY") & ".xlsm"
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

mehidy1437

Active Member
Joined
Nov 15, 2019
Messages
270
Office Version
  1. 2013
Platform
  1. Windows
  2. Mobile
  3. Web
Try,
VBA Code:
Sub Macro1()
'
' Macro1 Macro
'
Dim fname As String

fname = "P:\Buyers Files\Buyers Worksheets\" & Range("B2") & Format(Now(), " DD.MM.YY") & ".xlsm"
MsgBox fname
'relativePath = ActiveWorkbook.Path & "\" & fname
ActiveWorkbook.SaveAs Filename:=fname, FileFormat:=52

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,747
Messages
5,597,905
Members
414,189
Latest member
Duque_

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
Top