Run code generated from string

GlennL

New Member
Joined
Sep 25, 2018
Messages
37
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi,

I have this
Code:
If a = 56 Then b = session.findById("wnd[0]/usr/ctxtAEDAT-HIGH").Text

How do I get the
Code:
session.findById("wnd[0]/usr/ctxtAEDAT-HIGH").Text

part of the sting to run as normal code, since it comes now out of a sting?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
It’s not at all clear what you are trying to do. Are you saying that this returns a string that is valid VBA code that you then want to execute?

session.findById("wnd[0]/usr/ctxtAEDAT-HIGH").Text
 
Upvote 0
It’s not at all clear what you are trying to do. Are you saying that this returns a string that is valid VBA code that you then want to execute?

session.findById("wnd[0]/usr/ctxtAEDAT-HIGH").Text

This line of code
session.findById("wnd[0]/usr/ctxtAEDAT-HIGH").Text
is for OLE Automation. It already works just fine.

I now want to pull different text fields, based on conditions, so I have code like this:
Code:
Do While i < 57    
    If a = 1 Then b = session.findById("wnd[0]/usr/ctxtTLUSAGE-LOW").Text
    If a = 2 Then b = session.findById("wnd[0]/usr/ctxtTLUSAGE-HIGH").Text
    If a = 3 Then b = session.findById("wnd[0]/usr/ctxtMITYP-LOW").Text
    If a = 4 Then b = session.findById("wnd[0]/usr/ctxtMITYP-HIGH").Text
    If a = 5 Then b = session.findById("wnd[0]/usr/ctxtWARPL-LOW").Text
The challenge I have, is once
session.findById("wnd[0]/usr/ctxtAEDAT-HIGH").Text
is stored into 'b', the code is store as the string "
session.findById("wnd[0]/usr/ctxtAEDAT-HIGH").Text".

My question is: How do I get "
session.findById("wnd[0]/usr/ctxtAEDAT-HIGH").Text" to execute when I am getting "session.findById("wnd[0]/usr/ctxtAEDAT-HIGH").Text" from 'b'?


 
Upvote 0
By setting it to b, you are executing it. The value of b is whatever is retired from the text property of the code you posted.

It is not a string representation of the code.
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top