How to stop and save data on arduino board

I am a noobie and I found a code to send data to excel and then graph the data. my accelerometer keeps on collecting data, how can I make it stop collecting after some time?

my computer is not finding a program to open the example XL test for the gobetwino program.

this is what I have so far

int CS_pin = 9; //Chip select input; active low
int CLK_pin = 10; // Clock input
int DIO_pin = 11; // Data to/from the modual

int aX = 0;
int aY = 0;
int aZ = 0;

//// FUNCTIONS
void StartBit() { //declaring a function, funtion follows;
pinMode(DIO_pin, OUTPUT); //sets DIO_pin as output
digitalWrite(CS_pin, LOW); //sets CS_pin off
digitalWrite(CLK_pin, LOW); //Sets CLS-pin off
delayMicroseconds(1); //delay for 1 microsecond
digitalWrite(DIO_pin, HIGH); //Dio_pin On
digitalWrite(CLK_pin, HIGH); //CLK-pin on
delayMicroseconds(1); //delay for 1 microsecond

}

void ShiftOutNibble(byte DataOutNibble)
{
for(int i = 3; i >= 0; i--) //Loop, starts at 3, if it is greater than O then it subtracts 1 and starts the same loop over, if it is less than ) then goes to next step.
{
digitalWrite(CLK_pin, LOW); //CLK_pin off
// set DIO first
if ((DataOutNibble & (1 << i)) == (1 << i)) { // DataOutNibble AND 1 x 2^i Equals 1 x 2^i ?
digitalWrite(DIO_pin, HIGH);
}
else {
digitalWrite(DIO_pin, LOW);
}
// with CLK rising edge the chip reads the DIO from arduino in
digitalWrite(CLK_pin, HIGH);
// data rate is f_clk 2.0 Mhz --> 0,5 micro seeconds
delayMicroseconds(1); // :slight_smile: just nothing
}
}

void SampleIt() {
digitalWrite(CLK_pin, LOW);
delayMicroseconds(1);
digitalWrite(CLK_pin, HIGH);
delayMicroseconds(1);

pinMode(DIO_pin, INPUT);
digitalWrite(CLK_pin, LOW);
delayMicroseconds(1);
digitalWrite(CLK_pin, HIGH);
if (digitalRead(DIO_pin)== LOW) {
// Blink LED because ok
}
}

byte ShiftInNibble() {
byte resultNibble;
resultNibble = 0;

for(int i = 3 ; i >= 0; i--) { // from bit 3 to 0
// The chip Shift out results on falling CLK
digitalWrite(CLK_pin, LOW);
delayMicroseconds(1); // :slight_smile: just nothing
if( digitalRead(DIO_pin) == HIGH) { // BIT set or not?
resultNibble += 1 << i; // Store 1 x 2^i in our ResultNibble
}
else {
resultNibble += 0 << i; // YES this is alway 0, just for symetry :wink:
}
digitalWrite(CLK_pin, HIGH);
//delayMicroseconds(1); // :slight_smile: just nothing
}
return resultNibble;
}

void EndBit() {
digitalWrite(CS_pin, HIGH);
digitalWrite(CLK_pin, HIGH);
}

int GetValue(byte Command) { // x = B1000, y = B1001, z = B1010
int Result = 0;
StartBit();
ShiftOutNibble(Command);
SampleIt();
Result = 2048 - ((ShiftInNibble() << 8) + (ShiftInNibble() << 4) + ShiftInNibble());
EndBit();

return Result;
}

//// SETUP
void setup() {
Serial.begin(115200);
pinMode(CS_pin, OUTPUT);
pinMode(CLK_pin, OUTPUT);
pinMode(DIO_pin, OUTPUT);
// initialize device & reset
digitalWrite(CS_pin,LOW);
digitalWrite(CLK_pin,LOW);
delayMicroseconds(1);
digitalWrite(CS_pin, HIGH);
digitalWrite(CLK_pin,HIGH);
}

//// LOOP
void loop() {

aX = GetValue(B1000);
aY = GetValue(B1001);
aZ = GetValue(B1010);

Serial.print(aX);
Serial.print(" ");
Serial.print(aY);
Serial.print(" ");
Serial.print(aZ);
Serial.println("");
delay(1000); // loop every 100 times per sec.
}