Invoke Code Activity Question?

How to do PageDown Action in Notepad using Invoke Code Activity?I tried Send HotKey Activity but it doesn’t work.

Hi @Lakshmi_Tiliconveli

Use the below vb code in Invoke Code activity,

' Import the necessary namespaces
Imports System.Diagnostics
Imports System.Windows.Forms

' Define the path to the Notepad file
Dim filePath As String = "C:\path\to\your\notepad\file.txt"

' Start Notepad and open the file
Process.Start("notepad.exe", filePath).WaitForInputIdle()

' Perform PageDown action in Notepad
SendKeys.SendWait("{PGDN}")

Hope it helps!!

To perform a PageDown action in Notepad using the Invoke Code activity in UiPath, you can use the following VB.NET code within the Invoke Code activity:

System.Windows.Forms.SendKeys.SendWait(“{PGDN}”)

Make sure the Notepad application is in focus before the Invoke Code activity is executed for the keystroke to be sent to the correct application. If the Send Hotkey activity isn’t working, using SendKeys in an Invoke Code block often serves as a good alternative.

Please note, SendKeys is part of the System.Windows.Forms namespace, so the project needs to reference it. If it’s not available, you might need to adjust the project’s dependencies.

I would suggest to use the new Coded Workflows for this instead of Invoke Code in case you want a code solution.

I have used above code getting this error

System.ArgumentException: No compiled code to run
error BC30456: ‘SendKeys’ is not a member of ‘System.Windows.Forms’. At line 1
at UiPath.Core.Activities.ScopeActivity.OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

To resolve the error when using SendKeys in an Invoke Code activity in UiPath:

  1. Ensure Correct Namespace*: Add System.Windows.Forms to the Imported Namespaces of the Invoke Code activity.
  2. Use Fully Qualified Name*: In your code, use:

System.Windows.Forms.SendKeys.SendWait(“{PGDN}”)

  1. Focus on Notepad*: Before executing the Invoke Code, ensure Notepad is active using a Click activity on the Notepad window.
  2. Re-check Send Hotkey*: If the above doesn’t work, ensure Notepad is targeted correctly and retry the Send Hotkey activity with the Page Down key.

In case you still want to try with activities directly, I found no issues in getting this to work.



Hi @Lakshmi_Tiliconveli
Have you tried Recording in the Keyboard shortcut Activity

“I am glad that it worked for you. Thank you for letting me know.”

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.