SaveAs code

mcfly

Board Regular
Joined
May 15, 2002
Messages
162
Is there a way to save the worksheet as a pdf or just a read-only file that doesn't include the macros.

And also save the filename as "Quote" plus a number so that everytime you save this quote it will add a number to your sheet and also to the SaveAs filename

here is whats at the end of my finish button code:

msg = "Would you like to save this Quote?"
ans = MsgBox(msg, vbQuestion + vbYesNo, appname)
If ans = vbYes Then ActiveSheet.PrintOut
If ans = vbYes Then Unload Me
If ans = vbYes Then activeWorkbook.SaveAs

and that is all I can figure out can anyone of the code gurus help me out?

So whenever I select yes it will printout my sheet and at the same time save as a seperate file(read-only or pdf) named "Quote 000001"
and then the next time "Quote 000002".

Thanks in Advance!!!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You cant write a PDF file unless you have Adobe Acobate. Hers a suggestion on a save as routine.

Dim FileCount As Integer
Dim CurntBook As String
Dim Msg As String
Dim Ans
Dim SPath As String
Dim SFileName As String

Sub SaveIt()
'This requres a 2nd sheet to store the count
CurntBook = ActiveWorkbook.Name
SPath = "C:"
'get counter
If Workbook(CurntBook).Worksheet("Sheet2").Range("A1").Value < 1 Then
FileCount = 1
Else
FileCount = Workbook(CurntBook).Worksheet("Sheet2").Range("A1").Value
End If

Msg = "Would you like to save this Quote?"
Ans = MsgBox(Msg, vbQuestion + vbYesNo, appname)
If Ans = vbYes Then
Workbook(CurntBook).Worksheet("Sheet2").Range("A1").Value = FileCount 'write back counter
Sheets("Sheet1").Move 'to new workbook
SFileName = SPath & "Quote" & FileCount 'build filename
'save
ActiveWorkbook.SaveAs FileName:=SFileName, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=True, _
CreateBackup:=False
'print
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
'close
ActiveWorkbook.Close
Windows(CurntBook).Activate
End If
End Sub
 
Upvote 0
I hate be such a vba rookie but I've tried placing this in my userform code in a module in this workbook and I can't get it to work.
In my userform code I get the error sub or function not defined and it Highlight workbook under 'get counter
This message was edited by mcfly on 2002-10-18 08:51
 
Upvote 0

Forum statistics

Threads
1,206,920
Messages
6,075,573
Members
446,147
Latest member
homedecortips

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