Consulting

Results 1 to 7 of 7

Thread: CX-Server CDMDDE Visual Basic Macro Errors

  1. #1

    CX-Server CDMDDE Visual Basic Macro Errors

    Hello All,

    I am having some issues with Excel while communicating with the Omron PLC. The Excel file is getting the data from the PLC and the macro doing what I want to do, but I am getting the following error messages when opening the excel file.

    I am attaching the pictures of the messages and the code where debug send me.

    Thank you very much in advance

    59afc7ceb653b_updateerror.JPG.13f802fec873bc148dc2dc8c6b85bdda.JPG

    59afc82d96b20_run-timeerror.JPG.fa8149cd3f693c0f157193d0b2170d72.JPG

    code.JPG.86862c76f1f1825c6367939a3df9f67a.JPG

    code2.JPG.2aea9a33c4d9a7d13847c8a529d449ce.JPG

  2. #2
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    if you get an error in J2 you will get that message, so i suspect that when you open the workbook J2 has an error in it, try this modification:

    Private Sub Worksheet_Calculate()Static oldval As Variant
    If VarType(Range("$J$2").Value) <> vbError Then
    
    
        If Range("$J$2").Value <> oldval Then
         oldval = Range("$J$2").Value
        End If
    End If
    
    
    End Sub

  3. #3
    Thnk you offthelip for your quick answer.

    It almost works!

    Private Sub Worksheet_Calculate()Static oldval As Variant If VarType(Range("$J$2").Value) <> vbError Then


    If Range("$J$2").Value <> oldval Then
    oldval = Range("$J$2").Value
    Call Run
    End If
    End If

    End Sub
    I have added Call Run for calling the macro which is copying and pasting the data every time the value in J2 changes.

    Now I open Excel without problem, and it does it right the first times but after one time it doesnt work again.

    Any ideas??? almost there! I really appreciate it

    Thank you very much.

    Regards

  4. #4
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    and it does it right the first times but after one time it doesnt work again.
    what do you mean by this, a bit more detail is needed for us to help you

  5. #5
    Sorry,

    What I mean is. After opening the excel file from an external source I change the value in J2, When this happens code call Run macro.

    The Run macro copy and paste the values just one time.

    It is supposed that every time I change the value in J2 it should copy and paste the values in the first row in the next available row. But it only do it once.

    Thank you very much and sorry for my poor english


  6. #6
    Hello offthelip

    I am sorry, I do not know the reason it didn't work before, but now it's working.

    Thank you very much for your help I really appreciate it
    Last edited by elcharlie; 09-07-2017 at 07:18 AM.

  7. #7
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    looking further at your "Run" module one thing to be careful of is that you are modfying cells on the worksheet that you have got the worksheet calculate event trigger, this can cause problems and certainly will slow excel down even if it doesn't go into a loop.
    Can I suggtest that you turn events off before you copy the cells across and turn them on again afterwards, which you can do by modify the subroutine as below

    Private Sub Worksheet_Calculate()Static oldval As Variant
    If VarType(Range("$J$2").Value) <> vbError Then
    
    
        If Range("$J$2").Value <> oldval Then
         oldval = Range("$J$2").Value
         Application.EnableEvents = False
         Call Run
         Application.EnableEvents = True
        End If
    End If
    
    
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •