Hello, I am just dabbling in VBA so please be patient with me and try to use minimal technical terms... Basically, I created this Frankenstein of a code below by combining different codes I found online and writing some myself. It is not pretty, I am sure it can be written cleaner, but it works.
Basically what it does is that it cycles through a data validation range I have in one cell that fills up the form I have on one of the sheets with info from different employees. It then copies this form onto a temporary sheet, adds pagebreak, goes to another employee and adds it to the bottom of the last copy. In the end it prints a pdf file that has filled out forms for each employee on different pages.
What I am trying to do now is create a sort of table of contents on first page with hyperlinks to each employee. I have trouble with hyperlinks not working after I export them into pdf... I have read dozens and dozens of threads and I can't seem to figure it out. I am at my wits end... Is it even possible? Please help if you can, thanks!
Basically what it does is that it cycles through a data validation range I have in one cell that fills up the form I have on one of the sheets with info from different employees. It then copies this form onto a temporary sheet, adds pagebreak, goes to another employee and adds it to the bottom of the last copy. In the end it prints a pdf file that has filled out forms for each employee on different pages.
What I am trying to do now is create a sort of table of contents on first page with hyperlinks to each employee. I have trouble with hyperlinks not working after I export them into pdf... I have read dozens and dozens of threads and I can't seem to figure it out. I am at my wits end... Is it even possible? Please help if you can, thanks!
VBA Code:
Public Sub PrintCollated()
Dim PDFfullName As String
Dim PDFsheet As Worksheet
Dim destCell As Range
Dim wsName As Variant
Dim dataValidationCell As Range, dataValidationListSource As Range, dvValueCell As Range
Dim copyRange As Range
Dim i As Integer
PDFfullName = ActiveWorkbook.Path & "\" & ActiveWorkbook.Worksheets("InputList").Range("B9").Value
'Add temporary sheet for PDF output
With ActiveWorkbook
Set PDFsheet = .Worksheets.Add(After:=.Worksheets(.Worksheets.Count))
End With
Set PDFsheet = ActiveSheet
ActiveSheet.PageSetup.PaperSize = xlPaperA4
With PDFsheet.Range("A:N")
.ColumnWidth = 5.57
End With
With PDFsheet
.HPageBreaks.Add Before:=.Rows(.UsedRange.Rows.Count + 1)
Set destCell = .Cells(.UsedRange.Rows.Count + 1, 1)
'i = ActiveSheet.UsedRange.Rows.Count + 28
End With
'Set destCell = PDFsheet.Range("A1")
i = 28
'Loop through specified sheets
For Each wsName In Array("Report")
'Cell containing data validation in-cell dropdown
Set dataValidationCell = ActiveWorkbook.Worksheets(wsName).Range("I3")
'Source of data validation list
Set dataValidationListSource = Evaluate(dataValidationCell.Validation.Formula1)
'Set each data validation value in this sheet to update sheet cells
For Each dvValueCell In dataValidationListSource
dataValidationCell.Value = dvValueCell.Value
'Copy sheet cells to next cell in temporary PDF sheet
Set copyRange = dataValidationCell.Worksheet.UsedRange
dataValidationCell.Worksheet.Activate
copyRange.Select
Selection.Copy
PDFsheet.Activate
'destCell.Select
'ActiveSheet.Paste
destCell.PasteSpecial xlPasteValues
destCell.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
Range("A" & i).EntireRow.RowHeight = 20
Range("A" & i + 2).EntireRow.RowHeight = 9.25
Range("A" & i + 3).EntireRow.RowHeight = 16.25
Range("A" & i + 4).EntireRow.RowHeight = 9.25
Range("A" & i + 5).EntireRow.RowHeight = 16.25
Range("A" & i + 6).EntireRow.RowHeight = 9.25
Range("A" & i + 7).EntireRow.RowHeight = 16.25
Range("A" & i + 8).EntireRow.RowHeight = 9.25
Range("A" & i + 9).EntireRow.RowHeight = 16.25
Range("A" & i + 10).EntireRow.RowHeight = 9.25
Range("A" & i + 11).EntireRow.RowHeight = 16.25
Range("A" & i + 12).EntireRow.RowHeight = 9.25
Range("A" & i + 13).EntireRow.RowHeight = 16.25
Range("A" & i + 14).EntireRow.RowHeight = 12
i = i + 58
'Add page break and update destination cell
With PDFsheet
.HPageBreaks.Add Before:=.Rows(.UsedRange.Rows.Count + 1)
Set destCell = .Cells(.UsedRange.Rows.Count + 1, 1)
End With
Next
Next
'Save temporary sheet as .pdf file
PDFsheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfullName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
'Delete temporary sheet
'Application.DisplayAlerts = False
'PDFsheet.Delete
'Application.DisplayAlerts = True
'clear hyperlinks in workbook
'ThisWorkbook.Sheets("EmployeeList").Hyperlinks.Delete
End Sub