GetText only works in debugger mode, but with only with some users

Facu_

New Member
Joined
Jun 15, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I'm facing an issue with my code, when I try to save a string into a variable from SAP, first I copy that value(is a grid so the only way that I found to get the value is copying it) and then i save it into my variable.


When I use "GetText" most of the user of this tool are facing this issue (but not all of them, I don't know why):
1623765485852.png


When I jump into the debugger mode and I press F5 the tool continue and works properly, so I think that it's a configuration problem or something like that.

Here is the part of the code where I do this (the code is too long to share and also include SAP script that are not related):

'save the quantity of errors
Dim DataObj As New MSForms.DataObject
DataObj.GetFromClipboard
error_qty = DataObj.GetText


Do you have any idea where my code is failing or what kind of configuration could be generating this bug?

Thanks in advance
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
If you are just using the DataObject to get text from the clipboard, try the solution HERE instead.
 
Upvote 0
If you are just using the DataObject to get text from the clipboard, try the solution HERE instead.
Thank for your reply..
I've read that link but I cannot find anything related to my case..as I said It works in the debugger mode (pressing F5 or F8), but when I run from the trigger it crash using the "GetText".
I've already tried adding some wait seconds but nothing. I could also add more lines of my code in case it help to understand/find the issue, but I don't really find it useful.
 
Upvote 0
One needs to test if the clipboard contains text data before using GetText

VBA Code:
Dim DataObj As New MSForms.DataObject, error_qty As String

DataObj.GetFromClipboard

If DataObj.GetFormat(1) Then
    error_qty = DataObj.GetText
Else
    Rem clipboard contains non-text
End If

MsgBox error_qty
 
Upvote 0
One needs to test if the clipboard contains text data before using GetText

VBA Code:
Dim DataObj As New MSForms.DataObject, error_qty As String

DataObj.GetFromClipboard

If DataObj.GetFormat(1) Then
    error_qty = DataObj.GetText
Else
    Rem clipboard contains non-text
End If

MsgBox error_qty
Thanks for your reply.

I've tested the code you shared, I get the same error in the same line (the one painted in yellow in the image):
1623833709752.png


Of course when I run it in debugger it works :(
 
Upvote 0
I said It works in the debugger mode (pressing F5 or F8), but when I run from the trigger it crash using the "GetText".

What's the trigger?
Maybe the process of getting the text to clipboard hasn't completed yet?
Try :

VBA Code:
'save the quantity of errors
Dim DataObj As New MSForms.DataObject
  Application.Wait Now + TimeValue("0:00:03")
DataObj.GetFromClipboard
error_qty = DataObj.GetText

it will wait 3 second before get to "DataObj.GetFromClipboard"
 
Upvote 0
What's the trigger?
Maybe the process of getting the text to clipboard hasn't completed yet?
Try :

VBA Code:
'save the quantity of errors
Dim DataObj As New MSForms.DataObject
  Application.Wait Now + TimeValue("0:00:03")
DataObj.GetFromClipboard
error_qty = DataObj.GetText

it will wait 3 second before get to "DataObj.GetFromClipboard"
Thanks for your reply Akuini,

The trigger of my sub is in previous modules (it involves 7 differents modules with a bunch of lines, Idk if this could generate this problem).

I've tried adding the waiting seconds (even more than 3) and always the same.

Also mention that I get the copied value from SAP and I defined as Integer (also try as String but it's the same), idk if this is relevant..
 
Upvote 0
Hi everyone,

I'm facing an issue with my code, when I try to save a string into a variable from SAP, first I copy that value(is a grid so the only way that I found to get the value is copying it) and then i save it into my variable.


When I use "GetText" most of the user of this tool are facing this issue (but not all of them, I don't know why):
View attachment 40838

When I jump into the debugger mode and I press F5 the tool continue and works properly, so I think that it's a configuration problem or something like that.

Here is the part of the code where I do this (the code is too long to share and also include SAP script that are not related):

'save the quantity of errors
Dim DataObj As New MSForms.DataObject
DataObj.GetFromClipboard
error_qty = DataObj.GetText


Do you have any idea where my code is failing or what kind of configuration could be generating this bug?

Thanks in advance
An update of my issue, I've tried to paste data from my clipboard directly to a cell using:

Range("A1").PasteSpecial

Now it shows this message and again into de debugger works:
1623847278832.png
 
Upvote 0
What's in the clipboard?
I found out the problem is in there, the clipboard. When it crash what is storage in the windows and office clipboard is:

1623854170704.png


262 is the mentioned value extracted from SAP and the one that I want to store in "error_qty", the rest is previous information copied that I could delete from clipboard.

Thanks a lot MikeRickson
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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