BKNewton29
New Member
- Joined
- Sep 17, 2010
- Messages
- 30
Dear All,
I have a spreadsheet that dynamically changes ODBC data based on picking an item from a drop down menu.
I have now created a VB code to cycle through each branch on the drop down menu and print the resulting Profit and Loss to PDF.
However, the print to PDF command doesn't give the data enough time to auto refresh the data and resultant Profit and Loss.
Is there any way I can slow down the VB to allow the data to update?
current code set out below (Q is the column were branch numbers are plucked from)
Sub PrinttoPDF()
' Set variables used in Macro
Dim c As Range, strDefaultPrinter As String, strOutFile As String, branchname As String
strDefaultPrinter = Application.ActivePrinter
Application.ActivePrinter = "CutePDF Writer on CPW2:"
Application.ScreenUpdating = False
With Sheets("Branch Profit and Loss")
' pick each branch number from the list in column S
For Each c In .Range("Q1", .Range("Q1").End(xlDown))
' change the branch value in the drop down menu for each branch
.Range("C2").Value = c.Value
' recalculate once branch number has changed
Dim uniquename As String
' rename the filename after each branch ready for PDF export
uniquename = Range("R2").Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"H:\Accounts\2011\AXA Reporting\Branch Reports\" & uniquename & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Next c
End With
Application.ScreenUpdating = True
End Sub
I have a spreadsheet that dynamically changes ODBC data based on picking an item from a drop down menu.
I have now created a VB code to cycle through each branch on the drop down menu and print the resulting Profit and Loss to PDF.
However, the print to PDF command doesn't give the data enough time to auto refresh the data and resultant Profit and Loss.
Is there any way I can slow down the VB to allow the data to update?
current code set out below (Q is the column were branch numbers are plucked from)
Sub PrinttoPDF()
' Set variables used in Macro
Dim c As Range, strDefaultPrinter As String, strOutFile As String, branchname As String
strDefaultPrinter = Application.ActivePrinter
Application.ActivePrinter = "CutePDF Writer on CPW2:"
Application.ScreenUpdating = False
With Sheets("Branch Profit and Loss")
' pick each branch number from the list in column S
For Each c In .Range("Q1", .Range("Q1").End(xlDown))
' change the branch value in the drop down menu for each branch
.Range("C2").Value = c.Value
' recalculate once branch number has changed
Dim uniquename As String
' rename the filename after each branch ready for PDF export
uniquename = Range("R2").Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"H:\Accounts\2011\AXA Reporting\Branch Reports\" & uniquename & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Next c
End With
Application.ScreenUpdating = True
End Sub