I have a bunch of sheets I wish to save as pdf. I'm able to do so, but it keeps splitting my data into random bits. I would like to make a code that will remove all the page breaks such that it prints the pdf as one page. Any ideas on how to do this? Thanks! Below is a code I'm trying to use to remove the page break before saving the sheets as pdf, but it's not working.
Edit: I've tried looping it such that it removes all page breaks, but I'm having trouble making it stop once there is no more page breaks. Can anyone help me to make the loop end once all page breaks are gone?
Sub pdf2()
'saving the answers as pdf
Dim x As Integer
Dim y As Integer
Dim mywsname As String
Workbooks("Book1").Activate 'select workbook where sheets are at
For y = 1 To Application.Sheets.Count 'loop through and save all sheets as pdf
Sheets(y).Select
mywsname = ActiveSheet.Name
x = 1 'attempt to remove all page breaks
ActiveWindow.View = xlPageBreakPreview
For x = 1 To ActiveSheet.VPageBreaks.Count + 2
ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
Next x
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\TMSVC\docs\" & mywsname & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Next y
End Sub
ActiveSheet.PageSetup.FitToPagesWide = 1
andActiveSheet.PageSetup..FitToPagesTall = 1
if you just want to print it all on one page? You can try recording a macro while setting up the print page, and use that. – Christofer Weber