excel - 在打印 PDF 之前不更新值
问题描述
我最初的问题是:VBA 在运行期间不进行任何计算(复制、粘贴、应用公式),即使计算是自动定义的,即使screenUpdating
是True
这样,因为我导出了 PDF,它似乎缺少数据。只有在我关闭userform
它之前,它才会进行所有计算。所以一个技巧是unload Userform1
有效的,但很奇怪。
Private Sub CommandButton1_Click()
'some code for button1 on userform1 which should be already executed when I hit button2
End Sub
Public Sub CommandButton2_Click()
'this sub routine hide userform1 to userform2 and make more calculations
If UserForm1.ComboBox1.ListIndex <> -1 Then
'TextBox16.Value = ListBox2.Column(0, ListBox2.ListIndex)
Dim hFile As Workbook
Set hFile = ThisWorkbook
Dim rng1, rng2, rng3, rng4, rng44, rng5, rng6, rng7, rng8 As Range
Dim rngPM, rngDM, rngSE, rngH, rngW As Range
Set rng1 = hFile.Sheets("Promedio-Movil").Range("D6:D17") 'real 2019
Set rngPM = hFile.Sheets("Promedio-Movil").Range("I6") 'real ene 20
Set rng2 = hFile.Sheets("Movil-Doble").Range("D6:D17") 'real 2019
UserForm1.Hide
UserForm2.Show 'HERE THE PROBLEM, THIS SHOULD BE AT THE START
ActiveWorkbook.Sheets("Datos").Select
If UserForm1.ComboBox1.ListIndex = 0 Then
'Aguja-Espinal'
Range("B3:B14").Copy
rng4.PasteSpecial Paste:=xlPasteValues ' real 2018 holt
End If
'some more code to print PDF
End Sub
问题正是在上面的代码中,set
在我从userform1
to更改userform2
为说我在代码中间进行了更改之前,我正在使用其他代码,但是现在更改为 start 可以按预期工作。
'some more code using set here
Set rng8 = hFile.Sheets("DescomposicionSeries").Range("C2:C9")
UserForm1.Hide
UserForm2.Show 'these two lines to the start of the Sub routine
解决方案
推荐阅读
- node.js - 在 javaScript 中为 batchWriteItem(params,function(){}) 创建请求参数
- numpy - numpy 安装到 pypy3 虚拟环境中:`未定义的符号:cblas_sgemm`
- class - 矢量打印不正确的数据
- html - JSoup:获取维基百科页面摘要
- javascript - 在同一页面弹出窗口中显示来自另一个页面的模式内容
- vue.js - weex 输入数限制
- javascript - 映射存储在 Redux 存储中的 JSON 对象?
- iptables - 由于fail2ban,iptables变得巨大
- java - 如何在图书馆的活动中重用应用程序的工具栏?
- python - 如何从用户的选择中调用子程序