View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Option of Print Preview or Save As

Bob,

I wouldn't use a msgbox, I would use GetSaveAsFilename.

Here is an example

Sub findlastrow()
Dim lastrow As Long
Dim r As Range
lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Set r = ActiveSheet.Range("A1:P" & lastrow + 1)
r.PrintPreview

ans = MsgBox("Save file now?", vbYesNo)
If ans = vbYes Then
fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excle Files Files (*.xls), *.xls")
If fileSaveName < False Then
Activworkbook.SaveAs Filename:=fileSaveName
End If
End If

End Sub

As to saving a sheet against a workbook, no you can't do taht - directly.
What you can do is to copy that sheet to a new single sheet workbook, like

Sub findlastrow()
Dim lastrow As Long
Dim r As Range

ActiveSheet.Copy

lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Set r = ActiveSheet.Range("A1:P" & lastrow + 1)
r.PrintPreview

ans = MsgBox("Save file now?", vbYesNo)
If ans = vbYes Then
fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excle Files Files (*.xls), *.xls")
If fileSaveName < False Then
Activworkbook.SaveAs Filename:=fileSaveName
End If
End If

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bob Reynolds" wrote in message
...
Ok, since I'm not as familiar as I thought, I still need and answer to the
issue of the ws but
I tried to incorporate the code you sent me into the macro and I don't
understand where it goes, therefore I get an error.
Since I'm a novice can you explain a little more??
Thanks again
BOB

"Bob Reynolds" wrote in message
...
Thanks Bob,

What about if I want a msg box when yes is selected asking for the

filename?
Also is there a way to save just the worksheet instead of the workbook.

I'm looking at file size here where the ws is a lot smaller than the wb.
Thanks
BOB


"Bob Phillips" wrote in message
...
ans = mMsgBox "Save file now?", vbYesNo
If ans = vbYes Then
Activworkbook.SaveAs filename:="c:\myTest\myFile.xls"
End If

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bob Reynolds" wrote in message
.. .
Hello,
I have the following code in my spreadsheet that does a "Find last

row"
and
then gives me a print preview.

The missing link is how can I get it to "Save as" after the preview?

The
preview is used to make sure the "Findlastrow" worked and for

formatting.

It can be either a choice to to to a message box that asks do you

want
to
saveas or do you want to print preview? Obviously the selection

would
be
operators choice.....

Or can I put a save as dialog box into the print preview so that

once
it's
reviewed I can save it?

Sub findlastrow()
Dim lastrow As Long
Dim r As Range
lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Set r = ActiveSheet.Range("A1:P" & lastrow + 1)
r.PrintPreview
End Sub

Thanks
BOB