首页 > 解决方案 > 在打印 PDF 之前不更新值

问题描述

我最初的问题是:VBA 在运行期间不进行任何计算(复制、粘贴、应用公式),即使计算是自动定义的,即使screenUpdatingTrue这样,因为我导出了 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在我从userform1to更改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 

标签: excelvbapdf

解决方案


推荐阅读