PDA

View Full Version : VBA code to convert Excel file(including hiddenfiles)



Dhanu
09-24-2011, 07:48 AM
Hi I have an excel workbook designed macro with VBA codes. I want to convert excel sheets which are hidden in the PDF. I tried Call show sheet function but it ask to enter password. Is there any way that it automatically take password & open sheet,select range & convert it in PDF?
:think:

Kenneth Hobs
09-26-2011, 07:37 AM
Welcome to the forum!

Sub HiddenSheetsToPDF()
Dim fName As String, ws As Worksheet

For Each ws In Worksheets
If ws.Visible = xlSheetHidden Then
ws.Visible = xlSheetVisible
'ws.Unprotect "ken"
fName = ThisWorkbook.Path & "\" & ws.Name & ".pdf"
If Dir(fName) <> "" Then Kill fName
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
ws.Visible = xlSheetHidden
'ws.Protect "ken"
End If
Next ws
End Sub