function tsExcelActiveXSheetActivate(varargin) 
% TSEXCELACTIVEXSHEETACTIVATE is the callback for activesheet change action

% Author: Rong Chen 
% Revised: 
% Copyright 1986-2004 The MathWorks, Inc.
% callback 

if (strcmp(varargin{5}, 'SheetActivate'))
    h=varargin{1}.handle;
    % clear all the selections
    h.ClearEditBoxes;
    % check if the first column or row contains 
    h.checkTimeFormat(varargin{3}.Name,'both','1');
    % set correct absolute data/time if in the 1st col or row
    if h.IOData.formatcell.columnIsAbsTime>=0
        rangeStr=strcat('A1:A',num2str(h.IOData.originalSheetSize(varargin{3}.Index,1)));
        varargin{3}.Range(rangeStr).NumberFormat=cell2mat(h.IOData.formatcell.columnFormat);
        % update time panel
        set(h.Handles.COMBdataSample,'Value',1);
        h.TimePanelUpdate('column');
    elseif h.IOData.formatcell.rowIsAbsTime>=0
        rangeStr=strcat('A1:',h.findcolumnletter(h.IOData.originalSheetSize(varargin{3}.Index,2)),'1');
        varargin{3}.Range(rangeStr).NumberFormat=cell2mat(h.IOData.formatcell.rowFormat);
        % update time panel
       set(h.Handles.COMBdataSample,'Value',2);
       h.TimePanelUpdate('row');
    elseif h.IOData.formatcell.columnIsAbsTime==-1
        % update time panel
        set(h.Handles.COMBdataSample,'Value',1);
        h.TimePanelUpdate('column');
    elseif h.IOData.formatcell.rowIsAbsTime==-1
        % update time panel
       set(h.Handles.COMBdataSample,'Value',2);
       h.TimePanelUpdate('row');
    else
        % update time panel
       set(h.Handles.COMBdataSample,'Value',1);
       h.TimePanelUpdate('column');
    end
end
