Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrap Pasted Text In Attacmate 1

Status
Not open for further replies.

DizzyP

Technical User
Feb 27, 2012
26
US
I constantly paste from Outlook to Attachate. If the cpoied text is longer than the space available in Attachmate it does not continue to the next line. I want to write a macro that will wrap the text. My idea was to use the screen coordinates and maybe loop it. I am very new to VB so thank you in advance for bearing with me.
 

hi,

Use PutString!

You have to consider 1) the COLUMN where your string will start, 2) the number of characters on your screen.

Then you can write a loop to calculate how long the PutString can be and not get chopped off. You also need to know in what column the next line starts. Should be pretty simple.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Awesome! Thank you. I am running into the issue of syntax with the PutString. I can't figure out the syntax to Put the copied text rather than what I tell it to Put.
 


You'll have to access the ClipBoard to get the text into a variable.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Ok this is what I have.

' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping macro playback."
Stop
End If
Set Sessions = System.Sessions

If (Sessions Is Nothing) Then
MsgBox "Could not create the Sessions collection object. Stopping macro playback."
Stop
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 3000 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 Is Nothing) Then
MsgBox "Could not create the Session object. Stopping macro playback."
Stop
End If
If Not Sess0.Visible Then Sess0.Visible = True
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)

' The important stuff

Dim stuffToPaste As String
stuffToPaste = Clipboard.GetText()

Sess0.Screen.PutString stuffToPaste, Sess0.Screen.Cursor





System.TimeoutValue = OldSystemTimeout

End Sub


For some reason it's not reading what is pasted. It's telling me that the putstring line is not a valid method or function.
 


Code:
    Dim MyDataObj As MSForms.DataObject

    Set MyDataObj = New DataObject

    MyDataObj.GetFromClipboard

    MsgBox MyDataObj.GetText(1)

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
If that does not work then try this...
Code:
'credit to [URL unfurl="true"]http://akihitoyamashiro.com/en/VBA/LateBindingDataObject.htm[/URL]

    Dim MyDataObj As Object

    Set MyDataObj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

    MyDataObj.GetFromClipboard

    MsgBox MyDataObj.GetText(1)

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I was able to get the previous code to work. I'm not sure where to get the "code" section for the post, but here it is.

Dim stuffToPaste As String

stuffToPaste = Clipboard.GetText()

Sess0.Screen.PutString stuffToPaste, Cursor

I just removed the Sess0.Screen for the cursor because it was looking for that entire function, which did not exist.
No it's on to figuring out the loop. I'm sure i'll be bugging you more.
Thank you so much for the help so far!!
 
Ok, I don't even know where to start. Would you beable to point me in the right direction? I'm a newbie at VB.
 


SkipVought said:
You have to consider 1) the COLUMN where your string will start, 2) the number of characters on your screen.

...You also need to know in what column the next line starts.
Do we know THAT and if so WHAT?



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


Code:
Sub test()
    Dim iColStrt As Integer, iNbrCols As Integer, iColNxt As Integer
    Dim MyDataObj As Object, sCopied As String, iRow As Integer, iCol As Integer
    Dim p1 As Integer, pLen As Integer

    Set MyDataObj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

    MyDataObj.GetFromClipboard
    
    sCopied = MyDataObj.GetText(1)
    
    iColStrt = 70   'column where the 'paste' starts
    iRow = 1        'row where the 'paste' starts
    iNbrCols = 80   'number of columns on screen
    iColNxt = 60    'column where the 'paste' wraps to on the next line and following
    
    p1 = 1                      'parsing pointer start
    pLen = iNbrCols - iColStrt  'parsing string length
    iCol = iColStrt             'column to 'paste'
    Do While p1 < Len(sCopied)
        Sess0.Screen.PutString Mid(sCopied, p1, pLen), iRow, iCol 
        p1 = p1 + pLen              'next parsing pointer start
        pLen = iNbrCols - iColNxt   'next parsing string length
        iCol = iColNxt              'next columns to 'passte'
        iRow = iRow + 1             'next row to 'paste'
    Loop
    Set MyDataObj = Nothing
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I took this code snippet from somwhere else and tried to modify it to fit my needs. I need to start at 5,7 and the last on that line is 5,76. The area goes to 40,76.

Code:
 Dim stuffToPaste As String
    stuffToPaste = Clipboard.GetText()
    
    Dim stringLength As Long
    stringLength = Len(stuffToPaste)
    
    Dim endOfWord As Double
    endOfWord = 0
    

        
    While stringLength > 65
        
    endOfWord = InStr(startPosition, stuffToPaste, " ")
    If endOfWord = 0 Then
        Sess0.Screen.PutString 5, 7 = Mid(stuffToPaste, startPosition, stringLength)
GotToDone:
    Else
        Sess0.Screen.PutString 6, 7 = Mid(stuffToPaste, startPosition, (endOfWord - startPosition))
        startPosition = endOfWord + 1
Wend
I don't think this will work yet.
 
Again, thank you!!! I was able to get it to work with that logic. I was able to tweak it to make it start on the cursor so if the macro is run more than once it doesn't replace the previous.

Code:
iColStrt = Sess0.Screen.Col          
iRow = Sess0.Screen.Row              
iNbrCols = 75                    
iColNxt = iColStrt + 1              

parseStart = 1                          
parseLen = iNbrCols - iColStrt          
iCol = iColStrt                         
    
   Do While parseStart < Len(stuffToPaste)
    
  Sess0.Screen.PutString Mid(stuffToPaste, parseStart, parseLen), iRow, iCol
      parseStart = parseStart + parseLen
      parseLen = iNbrCols - iColNxt                          
      iCol = iColNxt                                          
      iRow = iRow + 1                                     
    Loop
    
    Sess0.Screen.MoveTo iRow, iCol

My challenge now is to figure out where to place the
Code:
InStr(70, stuffToPaste, " ")
to keep the words from cutting in half when wrapping.
 

to keep the words from cutting in half when wrapping.
In VB, there is a Split() function that parses a string based on a given delimiter. In this case, the delimiter would be SPACE and given SPACE as the delimiter, Split() would parse the sting into individual WORDS. So you could test the length of the string that is being placed on the screen, based on each individual word being concatenated to the string.

Unfortunately, EB does not have the Split() function, so you have to write your own, like...
Code:
Function SplitIt(s As String, d As String) As Variant
    Dim a() As String, idx As Integer
    Dim i As Integer, p1 As Integer, p2 As Integer
    
    p1 = 1
    For i = 1 To Len(s)
        If Mid(s, i, 1) = d Then
            GoSub ArrayMaint
        End If
    Next
    GoSub ArrayMaint
    
    SplitIt = a
    
    Exit Function
ArrayMaint:
    ReDim Preserve a(idx)
    p2 = i - p1
    a(idx) = Mid(s, p1, p2)
    p1 = p2 + p1 + 1
    idx = idx + 1
    Return
End Function

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Will it work in my current code? I have tried placing it multiple places. I guess I just don't understand the processing behind it all.
 


SplitIt() returns an ARRAY, that you need to process in your code. I'd use it up front, before the Do...Loop, to parse the 'pasted' string, and then use the array result in the loop.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I meant the InStr(). Will it work in my current code to accomplishe the same thing? I have tried but to no avail.
I really do appreciate your help and patience with me! :)
 


Please do not just say, "I have tried but to no avail."

If you want help, you need to provide clear, concise and complete information, which would include WHAT you tried, including code and WHAT the exact results were, including error messages and values.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top