none
Macro error

    Întrebare

  • I am working on a worksheet not created by me and until now the macro you can find below has always worked.

     

    Now I'm trying to work on the very same file on a 64bit Sony notebook, with excel 2007 and when i try to run this macro Iget the message "Method Range  of Object Global failed". I 'm thinking it'a problem of security settings in my excel but I've tried to chenge them also comparing the settings between a PC where the macro run and the one where the macro doesn't but without success.

     

    The only real difference is that on th PC where it doesn't work excel is in the English version while the PC where it works is the Italian version; could it depend on this?

     

    Thanks

     

     

    Sub Prova_no_iterazioni()
    '
    ' Prova_no_iterazioni Macro
    '

    ' Definizioni
        
        C01 = Range("CV3").Value
        C02 = Range("CV4").Value
        C03 = Range("CV5").Value
        C04 = Range("CV6").Value
        C05 = Range("CV7").Value
        C06 = Range("CV8").Value
        C07 = Range("CV9").Value
        C08 = Range("CV10").Value
        C09 = Range("CV11").Value
        C10 = Range("CV12").Value
        C11 = Range("CV13").Value
        C12 = Range("CV14").Value
        C13 = Range("CV15").Value
        C14 = Range("CV16").Value
        C15 = Range("CY3").Value
        C16 = Range("CY4").Value
        C17 = Range("CY5").Value
        C18 = Range("CY6").Value
        C19 = Range("CY7").Value



    ' Cancellazione iniziale
        
        Range(C02).Select
        Range(Selection, Selection.End(xlToRight)).Select
        Selection.ClearContents

        Range(C14).Select
        Range(Selection, Selection.End(xlToRight)).Select
        Selection.ClearContents

        Range(C19).Select
        Selection.ClearContents

        Range(C04).Select
        Selection.ClearContents

        Range(C06).Select
        Selection.ClearContents

        Range(C08).Select
        Selection.ClearContents

        Range(C10).Select
        Selection.ClearContents
        
        Range(C17).Select
        Selection.ClearContents
        
        Range(C12).Select
        Selection.ClearContents


    ' Ripristina rate massime per pagamento senior debt sculpted
        
            Range(C15).Select
            Selection.Copy
            Range(C17).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False


    ' Calcolo investimento complessivo e vendors' loan
        
        Dim A As Integer
        For A = 1 To 5
            
            Range(C18).Select
            Selection.Copy
            Range(C19).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            
            Range(C03).Select
            Selection.Copy
            Range(C04).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            
            Range(C05).Select
            Selection.Copy
            Range(C06).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            
            Range(C07).Select
            Selection.Copy
            Range(C08).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            
            Range(C11).Select
            Selection.Copy
            Range(C12).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
        
            Range(C09).Select
            Selection.Copy
            Range(C10).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
        
        Next A
        
        
    ' Calcolo rate per pagamento senior debt sculpted
        
            Range(C16).Select
            Selection.Copy
            Range(C17).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False


    ' Calcolo DSRA e quota breve periodo senior debt
        
        Dim B As Integer
        For B = 1 To 5
            
            Range(C13).Select
            Range(Selection, Selection.End(xlToRight)).Select
            Selection.Copy
            Range(C14).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False

            Range(C01).Select
            Range(Selection, Selection.End(xlToRight)).Select
            Selection.Copy
            Range(C02).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
        
        Next B


    ' Ritorno verso alto del foglio
        
        Range("E3").Select
        Range("A1").Select



    End Sub
    • Mutat de Kenneth LeeOwner 19 aprilie 2011 00:23 forum cleanup (From:MSDN, TechNet, and Expression Profile and Recognition System Discussions)
    23 februarie 2011 19:45

Toate mesajele

  • What exactly does this error mean:

    Is my idea to have a dll generate an event for Matlab simply not possible?
    - Is there a mistake in my code?

    - Am I choosing the wrong approach, is tehre a better way?

    ----------------------------------------------------------------------------------------------------

    The ComInterface.dll code:

    using System;
    
    using System.IO.Ports;
    
    
    
    namespace ComInterface
    
    {
    
     // Prototype for MatLab callback function
    
     public delegate void AnswerEvent(object sender, string msg);
    
    
    
     public class RS232
    
     {
    
     static SerialPort port;
    
     public static AnswerEvent matlabCallback;
    
    
    
     // Function to setup and open the serial port
    
     public static SerialPort Open(string portName)
    
     {reliable cars
    
     // Specify port settings
    
     port = new SerialPort(portName);
    
     port.BaudRate = 115200;
    
     port.Parity = Parity.Odd;
    
     port.StopBits = StopBits.One;
    
     port.Handshake = Handshake.None;
    
     port.ReadTimeout = 10;
    
     port.WriteTimeout = 10;
    
    
    
     // Open serial port
    
     if (! port.IsOpen)
    
     {
    
     port.Open();
    
     }
    
     
    
     // Clear runt buffer data
    
     port.DiscardInBuffer();
    
     port.DiscardOutBuffer();
    
    
    
     // Register serial port callback function
    
     port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
    
    
    
     // Just for debugging
    
     return port; 
    
     }
    
    
    
    
    
    
    
     // Function to read data from external device
    
     public static int ReadRegister(int addr, AnswerEvent fnc)
    
     {
    
     
    
     // Store Matlab callback function (could this be done differently?)
    
     matlabCallback = fnc;
    
    
    
     // Device stecific message protocol:
    
     // 1. Byte = Status (0x00 = Read)
    
     // 2. Byte = Address
    
     // 3.-6. Byte = 4 Byte Data
    
     byte[] sendMsg = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    
     sendMsg[1] = Convert.ToByte(addr);
    
    
    
     // Send read request to device
    
     port.Write(sendMsg, 0, 6);
    
    
    
     // Just for debugging
    
     return 1;
    
     }
    
    
    
    
    
    
    
     // Callback function from serial port
    
     public static void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
    
     {
    
     byte[] rcvMsg = new byte[6];
    
    
    
     // Read answer from external deice
    
     port.Read(rcvMsg, 0, 6);
    
    
    
     // Call event handler function in Matlab
    
     // => This leads to System error (Matlab crashes): ".NET unhandled exception: Asynchronous delegate invocation is not supported."
    
     matlabCallback(port, BitConverter.ToString(rcvMsg)); 
    
    
    
     // What happens here? Does program go to matlab and never come back? Is there another way to generate an event?
    
     // Better Question: Is MatLab still waiting to be called back???
    
     }
    
     }
    
    }
    15 iunie 2011 19:43