vba 如何使用VBA刷新单元格?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13513942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 14:28:50  来源:igfitidea点击:

How to refresh cells using VBA?

excelvba

提问by 0x90

I am using all the solutions that appear in:

我正在使用出现在以下位置的所有解决方案:

How to refresh ALL cell through VBA

如何通过VBA刷新所有单元格

Getting Excel to refresh data on sheet from within VBA

让 Excel 从 VBA 中刷新工作表上的数据

ActiveSheet.EnableCalculation = False  
ActiveSheet.EnableCalculation = True

or

或者

Application.Calculate

or

或者

Application.CalculateFull

None of them works in Excel 2010. When I go to the cell and right click refresh it works. How can I refresh within VBA?

它们都不适用于 Excel 2010。当我转到单元格并右键单击刷新时,它可以工作。如何在 VBA 中刷新?

Sheets("Name_of_sheet").Range("D424").Refreshraises an

Sheets("Name_of_sheet").Range("D424").Refresh提出一个

exception 438

异常 438

Questions:

问题:

  1. How can I make the script support Excel 2003, 2007, 2010?
  2. How can I choose the source file to refresh from using VBA?
  1. 如何让脚本支持 Excel 2003、2007、2010?
  2. 如何使用 VBA 选择要刷新的源文件?

EDIT:

编辑:

  1. I want to simulate a right mouse click and choose refresh in the menu in worksheet 3. That is the entire story.

  2. I work on an Excel file created 10 years ago. When opening in Excel 2010, I can go to a cell and right click on it and choose refresh and then choose the .txt file to refresh from. I am trying to do it automatically within VBA.

  1. 我想模拟鼠标右键单击并在worksheet 3. 这就是整个故事。

  2. 我处理 10 年前创建的 Excel 文件。在 Excel 2010 中打开时,我可以转到一个单元格并右键单击它并选择刷新,然后选择要刷新的 .txt 文件。我正在尝试在 VBA 中自动执行此操作。

采纳答案by Anirudh Ramanathan

You could try using Application.Calculation

你可以尝试使用 Application.Calculation

Application.Calculation = xlCalculationManual
Application.Calculation = xlCalculationAutomatic

回答by InContext

For an individual cell you can use:

对于单个单元格,您可以使用:

Range("D13").Calculate

Range("D13").Calculate

OR

或者

Cells(13, "D").Calculate

回答by 0x90

I finally used mouse events and keystrokes to do it:

我终于使用鼠标事件和击键来做到这一点:

Sheets("worksheet34").Select
Range("D15").Select
Application.WindowState = xlMaximized
SetCursorPos 200, 600 'set mouse position at 200, 600
Call mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0) 'click left mouse
Application.SendKeys ("R")

回答by LeeF

just a reminder;

只是提醒;

be careful when using

使用时要小心

Application.Calculation = xlCalculationManual
Application.Calculation = xlCalculationAutomatic

this sets the entire excel application to calculate formula's either automatically or manually. If you use

这将整个 Excel 应用程序设置为自动或手动计算公式。如果你使用

Application.Calculation = xlCalculationManual

you'll notice your automatic formulas no longer work.

您会注意到您的自动公式不再有效。

cheers

干杯