Make macro that saves a file

Jyggalag

Active Member
Joined
Mar 8, 2021
Messages
445
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all,

I would like to create a macro where, once I press it, it saves my file to my folder \\COMPANY.MDDD.COMPANY.NET\userdata\t654895\home\Documents\test files

Does anybody know how I would go about in doing this? :)

Thank you!

BR.
Jyggalag
Prince of Order est. March 26, 2007.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hello Jyggalag,

This should help.

ActiveWorkbook.SaveAs Filename:="C:\JyggalagFile.xlsm"
ActiveWorkbook.SaveAs Filename:="\\COMPANY.MDDD.COMPANY.NET\userdata\t654895\home\Documents\test files\JyggalagFile.xlsm"

Jamie
 
Upvote 0
Hello Jyggalag,

This should help.

ActiveWorkbook.SaveAs Filename:="C:\JyggalagFile.xlsm"
ActiveWorkbook.SaveAs Filename:="\\COMPANY.MDDD.COMPANY.NET\userdata\t654895\home\Documents\test files\JyggalagFile.xlsm"

Jamie
Thank you so much Jamie!

I assume that I should just put "Sub" before the code and "End Sub" after to make it work in VBA, right?

Would there be any way in which you could make the SaveAs FileName = a cell value in Excel? :)

Kind regards,
Jyggalag
 
Upvote 0
Yes you put sub before and end sub after.

I think you can set the filename to a cell value, I did something similar before. I will look at it tomorrow if I remember.
 
Upvote 0
Hello,

VBA Code:
Sub CellFromFilename()
Dim Path As String
Dim fn As String
Path = "C:\Users\Jamie\Desktop\Developing\"
fn = Range("A1")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xls", FileFormat:=xlNormal
End Sub

I would forget tomorrow. :)

Jamie
 
Upvote 0
Solution
Hello,

VBA Code:
Sub CellFromFilename()
Dim Path As String
Dim fn As String
Path = "C:\Users\Jamie\Desktop\Developing\"
fn = Range("A1")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xls", FileFormat:=xlNormal
End Sub

I would forget tomorrow. :)

Jamie
Hi Jamie,

Thank you so much for your guidance and incredibly fast answers! Apologies for my slow one :)

I have one error when I run the code now, please see below:

1643721660568.png


It highlights "Filename". Any idea where I may have messed up?

Kind regards,
Jyggalag
 
Upvote 0
Hi Jamie,

Thank you so much for your guidance and incredibly fast answers! Apologies for my slow one :)

I have one error when I run the code now, please see below:

View attachment 56648

It highlights "Filename". Any idea where I may have messed up?

Kind regards,
Jyggalag
I think he meant to use "fn" there, and not "FileName", as there are no variables named "Filename" declared in that procedure (but there is one named "fn").
 
Upvote 0
Z
I think he meant to use "fn" there, and not "FileName", as there are no variables named "Filename" declared in that procedure (but there is one named "fn").
You're right! Thank you so much Joe4! I'll allow Jamie to receive the solution, but would highlight yours in addition if I could! :)
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,174
Members
452,615
Latest member
bogeys2birdies

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