Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

second macro to run before the first one has completed

Posted on 2014-01-09
4
Medium Priority
?
276 Views
Last Modified: 2014-01-09
Hi Expert's Excel 2007

I have a macro which does a simple copy cut and paste special. ..works great...however..I need a macro to prompt the user to save the file first before the copy and paste macro runs. ..just in case they accenditally press the copy and paste macro button by error and delete all the formula. ..

both macros to run off one button. ...ill simply call the other macro..
0
Comment
Question by:route217
  • 2
4 Comments
 
LVL 14

Assisted Solution

by:Alexander Eßer [Alex140181]
Alexander Eßer [Alex140181] earned 1000 total points
ID: 39767867
You could override "Workbook_BeforeSave" as shown here http://datapigtechnologies.com/blog/index.php/forcing-users-to-save-as-xlsm/ and then just save your workbook from within VBA before calling your macro...
0
 

Author Comment

by:route217
ID: 39767915
Ok thanks for the feedback...how do I call the private sub. ...

these guys have no vlue on vba....do everything had to run via a button. ..
0
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 1000 total points
ID: 39767929
HI,

you coud try this

Sub MacroSaveBefore()
Result = MsgBox("Do you want to save your workbook before" & vbCrLf & "replacing the formulas with values?", vbYesNo, "Paste values")
If Result = vbYes Then
    ActiveWorkbook.Save
End If
'Rest of your code

End Sub

Open in new window


EDIT  a bit more sophisticated
Sub MacroSaveBefore()
Result = MsgBox("Do you want to save your workbook before" & vbCrLf & "replacing the formulas with values?", vbYesNoCancel, "Paste values")
If Result = vbYes Then
    ActiveWorkbook.Save
ElseIf Result = vbCancel Then
    MsgBox "Operation cancelled", vbOKOnly, "Stop"
    Exit Sub
End If
'Rest of your code

End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:route217
ID: 39767948
Thanks for the excellent feedback. .
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question