输出宏执行步骤

时间:2016-04-22 12:31:15

标签: excel excel-vba vba

有没有办法实时显示宏执行步骤?
防爆。

Sub activate_sheets()
Worksheets("s1").Activate
'some code
Worksheets("s2").Activate
'some code
........    
End Sub  

我想在执行期间看到s1是否被处理,然后是否处理了s2等。

像这样 codeline1 - 已处理的 codeline2 - 已处理的 ...
换句话说,某些“即时窗口”,但不是在vba模式中 谢谢

2 个答案:

答案 0 :(得分:0)

您可以使用Debug.Print(“”)在调试窗口中写入日志。

Sub activate_sheets()
  Worksheets("s1").Activate
    'some code
    debug.print ("worksheet S1 processed")
  Worksheets("s2").Activate
    'some code
    debug.print ("worksheet S2 processed")
  End Sub  

但是,仅当您从Visual Basic编辑器执行宏时才会这样做。如果您希望让用户能够查看已处理的步骤,则可能需要显示自定义表单并创建某种类型的进度条。这是我主要使用的 - 用户喜欢看进度条。

请在http://www.filedropper.com/progressbartest找到示例文件 - 我匆忙建立了它。但它至少会给你一个想法...

答案 1 :(得分:0)

使用 ALT + F11 打开VBA编辑器,单击代码内部并按F8。每按一次F8,它会逐步执行代码。要在工作表上查看结果,请切换到工作表并查看。要查看变量值,只需将鼠标悬停在代码中,当前值将在智能感知窗口中弹出。您甚至可以通过键入 while(true) { boolean status = true; //represents the status of the process System.out.print("Enter the number of students that you wish to be part of the module register: "); int numofstudents = input.nextInt(); try{ if (input.nextLine().equals("exit")) {System.exit(0);} status = true; }catch (InputMismatchException IME){ /*3*/ System.out.println("\nNot a number or an integer!\n"); status = false; continue; } finally{ if (status==false) { String[] names = new String[numofstudents]; int[] array = new int[numofstudents]; for(int i = 0; i < numofstudents; i++) { System.out.print("Enter the student's name: "); names[i] = input.next(); System.out.print("Enter the student's module: "); array[i] = input.nextInt(); } selectionSort(names, array); System.out.println(Arrays.toString(names)); System.out.println(Arrays.toString(array)); Scanner scan = new Scanner(System.in); } }} 后跟变量或对象的属性来使用Immediate Window来查看当前值。

或者,您可以在每行后使用?语句。