Firstly, Hello! I've used this forum for many years as a useful tool when trying to find solutions to automate many of my work tasks over the years. I've never needed to post a question as I've always found a solution already on the forum. Thank you for all the help over the years!
I was wondering if someone could review the code I'm currently using to see if there is a way to speed up the process. When I pull my invoices from D365 to excel, there are formatting changes I need to do before I can print and it needs to loop through every worksheet in the workbook. Depending on the amount of orders for a specific customer there can be 100-250 worksheets that need to be formatted before printing.
Thank you for your time.
I was wondering if someone could review the code I'm currently using to see if there is a way to speed up the process. When I pull my invoices from D365 to excel, there are formatting changes I need to do before I can print and it needs to loop through every worksheet in the workbook. Depending on the amount of orders for a specific customer there can be 100-250 worksheets that need to be formatted before printing.
VBA Code:
Sub Invoice1SetUp()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Sheets
ws.Select
Call xruncode
Next
Application.ScreenUpdating = True
End Sub
Private Sub xruncode()
'
' Macro1 Macro
'
'
Range("G15:J16").Select
Selection.VerticalAlignment = xlBottom
Range("Y1:AD1").Select
Selection.ClearContents
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.RightHeader = "Page &P of &N"
.LeftMargin = Application.InchesToPoints(0.2)
.RightMargin = Application.InchesToPoints(0.2)
.TopMargin = Application.InchesToPoints(0.2)
.BottomMargin = Application.InchesToPoints(0.2)
.HeaderMargin = Application.InchesToPoints(0.2)
.FooterMargin = Application.InchesToPoints(0.2)
.Orientation = xlPortrait
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.FitToPagesWide = 1
.FitToPagesTall = False
.PrintTitleRows = "$1:$22"
Dim r As Range
For Each r In ActiveSheet.UsedRange
Dim length As Integer
length = Len(r.Value)
If length >= 57 Then
r.RowHeight = 25.75
Rows("12:12").RowHeight = 51
Rows("20:20").RowHeight = 23
End If
Next r
End With
End Sub
Thank you for your time.