Create a macro for "save as" and "print"

josullivan601632

New Member
Joined
Aug 23, 2020
Messages
39
Office Version
  1. 2007
Platform
  1. Windows
I want to use a "SAVE AS" and "PRINT" icon (already placed in spreadsheet) and assisgn a macro for each; I rightclick the image and "assisgn a macro", > new ...but this is where I get stuck, everything I try does not work! For the "Save As" I want the file to be given the numerical content of cell A2 (currently a numerical value) + plus current date and be saved in a specified folder.

For the print, I just want the user to be able to click on the icon and the 3 page spreadsheet be printed.

I believe the above is possible but I am not clever enough :(

Any suggestion would be appreciated.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Do these tasks manually with the macro recorder running and see what/how Excel does it.
It won't be exactly what you want but a very good place to start.
 
Upvote 0
Thank you, I have got so far and learnt alot! Printer one I have done works great.

The Save As I am struggling with recording the macro from the save button I have inserted. I have a code that I think I'm getting close with, not sure how to "word" as the macro I am recording has a differerent name, I have:

Sub SaveAsA2()

ThisFile=Range("A2"). (Value)&Format, "mm-dd-yyyy") & ".xlsm"
ActiveWorkbook.SaveAs Fileman:=ThisFile

End Sub

Any guidance to correc this, I am sure its in the language!
 
Upvote 0
VBA Code:
Sub SaveAsA2()

thePath = ThisWorkbook.Path & "/"
thisFile = Range("A2").Value & "-" & Format(Date, "mm-dd-yyyy")
fullFilename = thePath & thisFile

ActiveWorkbook.SaveAs fullFilename, 52

End Sub

put your cursor in the macro on the word SaveAs and hit F1 to see the VBA help file and find out why the 52 and no .xlsm
 
Upvote 0
Thank you so much for our response. I am being a bit thick obviously because I don't understand. I copied the code, it returned an error as proof I did it wrong!! where it says 'fullFilename' do I overtype 'Saved Buyers Worksheets' which is the folder I want it saved to, where is say 'Path' do I overtype the path 'SHARED (\\DiskStation) (P:)'
 
Upvote 0
you type the full path to the folder you want it saved in on the right side of the thePath= equal sign
you type the name you want for the file on the right side of the thisFile= equal sign

fullFilename is a variable that uses the other two variables so you don't have to type it all out in the SaveAs line
 
Upvote 0
Thanks, so this is what I have:

Sub SaveAsA2()

thePath = P:\Buyers Files\Saved Buyers Worksheets
thisFile = Range("A2").Value & "-" & Format(Date, "mm-dd-yyyy")
fullFilename = thePath & thisFile

ActiveWorkbook.SaveAs fullFilename, 52

End Sub

Results in:
Compile error:
Syntax error

Have I misunderstood you?
 
Upvote 0
likely missing the separator "/" on the end of thePath
 
Upvote 0
This is the marco, copied and pasted:-

Sub SaveAsA2()

thePath = P:\Buyers Files\Saved Buyers Worksheets\
thisFile = Range("A2").Value & "-" & Format(Date, "mm-dd-yyyy")
fullFilename = thePath & thisFile

ActiveWorkbook.SaveAs fullFilename, 52

End Sub

Still says
Compile error:
Syntax error

Would anybody be prepared to test this for me?
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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