my $code = <<'END_CODE'; Sub dosomething(say As String) For Each cell In ActiveSheet.Range("A1:A10") cell.Value = say Next cell End Sub END_CODE my $codemodule = $mod->Codemodule; $codemodule->AddFromString($code); $xlApp->Run( 'dosomething', 'test...' );