Solved

second macro to run before the first one has completed

Posted on 2014-01-09
4
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Assisted Solution

by:Alexander Eßer [Alex140181]
Alexander Eßer [Alex140181] earned 250 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 50

Accepted Solution

by:
Rgonzo1971 earned 250 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

756 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