I have two subroutines:CommandButton2_Click,CommandButton1_Click in which cmd2_click will call cmd1_click by using the below statement:
Application.OnTime Now() + TimeValue("00:00:15"), "CommandButton1_Click"
But I'm getting the below error while executing the above statement.
here is a screen shot of error
Kindly prefix the programatic sheetname followed by a dot as in below example.
Try below code :
Application.OnTime Now() + TimeValue("00:00:15"), "Sheet1.CommandButton1_Click"
If you search for CommandButton1_Click procedure in object browser you will see its a private function on the sheet in which you have kept the command button.
Also make sure your macro is enabled. Kindly refer below link.
http://www.youtube.com/watch?v=3Jqp_WQRT6M
Related
I am automating a website. I am using SeleniumBasic in Excel VBA.
I have a simple Pop-Up, or Alert, with an OK button.
I cannot access the Pop_Up by using Inspect so I have no HTML to show.
When the Pop-Up occurs, I respond with Driver.SwitchToAlert.Accept. It goes away, as desired.
I don't know how to check programmatically if the Pop-Up is present.
If I assume that the Pop-Up may have occurred and use this code on a just-in-case basis, i.e. use the code without the Pop-Up existing, the program stops without any error message.
Is there a way to check if the Pop-Up window exists before I respond?
Well, I found the answer:
I got this code from someone who got it from someone else.
Private Function AlertIsPresent() As Boolean
'Returns true if an alert is present, false otherwise
Dim T As String
On Error Resume Next
T = Driver.Title 'This raises error 26 if an alert(pop-up) is displayed
AlertIsPresent = (26 = Err.Number)
End Function
If function returns 'true', use the Driver.SwitchToAlert.Accept to close it.
I would like to create/use toasters notifications on Excel. Because we already use MsgBox to notify the user that something happen.
But it make the script to stop (pause).
Have you any idea of how to do ?
On google there is "System Tray Notification" but it need a lot of code and this is a old method. Can't find if there is a new method.
For example, the plugin from SAP : "Analysis For Office" put notifications on Excel.
I looked into this once and almost gave up on it entirely until I found a rather 'cheaty' way of alerting users of info without suspending execution, that works on my users machines.
We run Windows 10 here and have SCCM installed for software distribution and updates. I've absolutely no idea if that's mandatory in Windows for updates or not, so I've no idea if this works for you.. but the following code works a treat here if you don't mind the notification resembling a Software Centre notification:
Sub Toastnote(ccmTitle, ccmText)
Shell "c:\windows\ccm\sctoastnotification.exe """ & ccmTitle & """ """ & ccmText & """ "
End Sub
You can call it with:
toastnote "title goes here","message goes here"
It creates a little pop-up that looks like this:
As I say, it's a bit of a cheat and might confuse users who regularly receive CCM notifications, but for my user-base that wasn't an issue.
Lastly, it's probably worth wrapping this in an IF statement that checks the .exe file exists - just a thought..
Using the Plugin "Analysis For Office" from SAP, you can define messages and add them to the standard SAP-AnalysisForOffice message dialog :
Dim lResult As Long
lResult= Application.Run("SAPAddMessage", "This is a new error message!", "ERROR")
The message 'This is a new error message' with severity Error is displayed in the message dialog.
It will do the same as the picture sent with my question.
Source
Details about SAPAddMessage
I had a similar requirement (mainly for debugging)
My solution was to pop up a small form with a single label control and unload it 4 seconds later. The form proeprties are set no not show modal etc.
in a VBA "Module"
Private mFrmToast As frmToast
Public Sub clearToast()
On Error Resume Next
If Not mFrmToast Is Nothing Then
mFrmToast.Hide
Unload mFrmToast
Set mFrmToast = Nothing
End If
End Sub
Public Sub showToast(message As String)
On Error GoTo er_clear_in_4
If mFrmToast Is Nothing Then
Set mFrmToast = New frmToast
End If
mFrmToast.message = message
If Not mFrmToast.Visible Then
Call mFrmToast.Show(False)
End If
er_clear_in_4:
Application.OnTime Now + TimeValue("00:00:04"), "clearToast"
End Sub
The form "code behind" module contained a sample write only property, "message".
Option Explicit
Public Property Let message(ByVal sMessage As String)
lblMessage.Caption = sMessage
End Property
The usage is simply
showToast("your message here")
I am using same Splash Screen User Form for 3 years in my company but today it started giving Method 'Wait' of object '_Application' failed error.
I am assuming this is related to New Microsoft Share Point (previously we were using our internal share point now using cloud)
I tried to search on SO but nothing exactly same. (i.e: Method 'VBE' of object '_Application' failed)
I tried deleting the extra paranthesis but no change...
I am thinking of adding On Error statement but if my splash screen won't pop-up why would I have this code & user form? So honestly rather than On Error statement I want to have a real solution.
Application.Wait (Now + TimeValue("00:00:01"))
SplashUserForm.Label1.Caption = "Opening..."
SplashUserForm.Repaint
Application.Wait (Now + TimeValue("00:00:01"))
Unload SplashUserForm
Application.OnKey "{F7}", "showContains"
*An Error comes straight away when it comes to Application.Wait (Now + TimeValue("00:00:01"))
UPDATE
After reviewing Stax' suggestion as per his comment once I change the Application object with CreateObject("Excel.Application") this fixes the first problem which is Wait method. But then the next line OnKey method doesn't work with CreateObject("Excel.Application").
You can use Application.ScreenUpdating=False and it goes quicker.
I googled and SO'd, and nothing.
My job revolves around making my co-workers lives easier.
Currently, they are using very clunky spreadsheets designed 10+ years ago.
In the process of migrating their tools and reports to the local intranet using PHP, i have configured a spreadsheet that downloads that persons permissions based on their Application.Username
Then a little back and forth with the server to generate a session key, and then pop internet explorer opens up with the relevant tool they selected from a dropdown within the workbook - meaning their session and tools are then purely browser based.
All works great, however randomly, sometimes, when the sub to open the internet browser is triggered a very bizarre error message appears :-
Upon clicking Debug, the following function is shown, and you can see for yourself which line is highlighted in yellow.
I can confirm i do not have any tasks at all within my taskschedule. When i end this, and run it again, chances are it runs just fine.. it is just sometimes that this error pops up.
Please help! Thank in advance.
With errors this seemingly-unrelated and intermittent, I usually opt for either a bit of delay, catching the error and retrying or both.
Try the following (retry without a delay):
Function gogogo(sessKey)
On Error GoTo ErrHandler
reportId = Sheet2.Range("A" & (Sheet2.Range("B1").Value + 1)).Value
Set objIE = CreateObject("InternetExplorer.Application")
URL = "http://localinternetdomainhere/OnlineTools/" & reportId & "/access/" & sessKey
With objIE
.Visible = True
.navigate URL
End With
ThisWorkbook.Saved = True
ThisWorkbook.Close False
Exit Function
ErrHandler:
If Err.Number = &H800704A6 Then 'Put a breakpoint here to make sure this is the ACTUAL VBA error number and not the ActiveX one. You might need to check against the Err.LastDllError property
Resume
End If
Err.Raise Err.Number, Err.Source, Err.Description,err.HelpFile, err.HelpContext 'Reraise the error otherwise
End Function
I'm trying to clean up my code on save using Resharper's Cleanup Code function. I made a macro that handles DocumentSaved events. The important parts:
Private Sub DocumentEvents_DocumentSaved(ByVal document As EnvDTE.Document) _
Handles DocumentEvents.DocumentSaved
...
DTE.ExecuteCommand("ReSharper_SilentCleanupCode")
document.Save()
End Sub
Every time I save, I get an exception message that says Error HRESULT E_FAIL has been returned from a call to a COM component. Any ideas?
Note: I see How can I configure ReSharper's code cleanup on save? and it won't work in my situation because I need to respond to the save event. Mapping a macro to CTRL+S isn't enough.
I think this is because when you call document.Save() it is recursing and saving again and then it falls over. Try this:
Private Sub DocumentEvents_DocumentSaved(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentSaved
Static currentDocument As EnvDTE.Document
If Not currentDocument Is Document Then
currentDocument = Document
DTE.Windows.Item(Document.Name).Activate()
DTE.ExecuteCommand("ReSharper_SilentCleanupCode")
DTE.ActiveDocument.Save()
End If
End Sub
This worked for me