on 2016 Feb 17 4:06 PM
Hello. I have an input form with 2 sheets and i need to make the button 'Save data' which is situated on EPM ribbon and adjusted default to work as 'save and refresh worksheet data', to work as 'save and refresh workbookdata'. I have written this macro but still have some problems:
Function BEFORE_SAVE()
Dim epmapi_L As Object
Set epmapi_L = Application.COMAddIns("FPMXLClient.Connect").Object
If saveflag = False Then
ask = True
epmapi_L.SetUserOption "HideSubmitWarning", False
Call Save_workbook
End If
If ask = False Then
Exit Function
End If
End Function
________________________________
Public Sub Save_workbook()
Application.ScreenUpdating = False
Dim epmapi As Object
Set epmapi = Application.COMAddIns("FPMXLClient.Connect").Object
saveflag = True
epmapi.SaveAndRefreshWorkbookData
ask = False
End Sub
_____________________________
Function AFTER_SAVE()
saveflag = False
End Function
The problems are:
Maybe someone had experience with task like this, will be grateful for help.
Request clarification before answering.
Tested code for your scenario:
' Set WinAPI Timer
Public Declare Function SetTimer Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
' Kill WinAPI Timer
Public Declare Function KillTimer Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
' Global var for timer
Public lngTimerID As Long
Dim epm As New FPMXLClient.EPMAddInAutomation
Dim blnSave As Boolean
Function BEFORE_SAVE() As Boolean
If Not blnSave Then
BEFORE_SAVE = False
epm.SetUserOption "HideSubmitWarning", False
blnSave = True
lngTimerID = SetTimer(0&, 0&, 100&, AddressOf TimerProc)
Else
BEFORE_SAVE = True
End If
End Function
Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
If nIDEvent = lngTimerID Then
KillTimer 0&, lngTimerID
epm.SaveAndRefreshWorkbookData
blnSave = False
End If
End Sub
Vadim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vadim,
I am trying to capture the save worksheet result in the macro.If the pop up message says "data save is failed" or if "there is no data to save", I don't want to proceed further. If the data save is successful then I have other actions to perform after save.
I am using a macro button to invoke save data. is there a way to capture that event using vb code.
I appreciate your inputs.
Best regards,
Sailu
Vadim, thanks for your help!
Tried your code and it works.
I have fixed my code and it seems to work as it should too:
Function BEFORE_SAVE()
Dim epmapi As Object
Set epmapi = Application.COMAddIns("FPMXLClient.Connect").Object
If saveflag = False Then
saveflag = True
BEFORE_SAVE = False
epmapi.SaveAndRefreshWorkbookData
Exit Function
ElseIf saveflag = True Then
saveflag = False
End If
BEFORE_SAVE = True
End Function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexey,
You are doing slightly strange things
I recommend you to understand sequence of events - just add:
Debug.Print "something"
to BEFORE_SAVE, AFTER_SAVE, BEFORE_REFRESH, AFTER_REFRESH
And you will see how it's working Just look on Immediate window in VBA Editor. Don't use MessageBox!
Vadim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 6 | |
| 3 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.