Having a bit of trouble with some VBA i Have.
The workbook is made up of multiple worksheets, and the code is designed to look at all sheets that have an entry in Cell C6, if there is an entry then it will collate that worksheet, and check the rest. once all worksheets with an entry in cell c6 are obtained, a pdf report is made from these selected worksheets.
this used to work, but for some reason its not now.
the code is as follows:
When the button that this code is attached to is pressed (on the first worksheet) the first pop up appears asking for folder location, then when you click ok, the next pop up appears asking for file name, when you click ok, it then errors, with
Select method of Worksheet class failed.
and the following line in the code is highlighted
Worksheets(Split(Left(strWS, Len(strWS) - 1), cstrDel)).Select
Can anybody shed any light on why this might be happening
The workbook is made up of multiple worksheets, and the code is designed to look at all sheets that have an entry in Cell C6, if there is an entry then it will collate that worksheet, and check the rest. once all worksheets with an entry in cell c6 are obtained, a pdf report is made from these selected worksheets.
this used to work, but for some reason its not now.
the code is as follows:
VBA Code:
Private Sub createpdf_Click()
Dim ws As Worksheet
Dim strWS As String
Dim strFolder As String
Dim varRet As Variant
Const cstrDel As String = ","
'getting information about the sheets
For Each ws In Worksheets
If ws.Range("C6").Value <> "" Then
strWS = strWS & ws.Name & cstrDel
End If
Next ws
'getting the folder to which to save to
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then
strFolder = .SelectedItems(1) & "\"
Else
Exit Sub
End If
End With
'getting the filename to save
varRet = Application.GetSaveAsFilename(InitialFileName:=strFolder, _
fileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Save Report to Directory")
'if Cancel is chosen varRet will returm False
If varRet <> False Then
'group the worksheets
Worksheets(Split(Left(strWS, Len(strWS) - 1), cstrDel)).Select
'print to PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=varRet, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True 'display after creation?
End If
End Sub
When the button that this code is attached to is pressed (on the first worksheet) the first pop up appears asking for folder location, then when you click ok, the next pop up appears asking for file name, when you click ok, it then errors, with
Select method of Worksheet class failed.
and the following line in the code is highlighted
Worksheets(Split(Left(strWS, Len(strWS) - 1), cstrDel)).Select
Can anybody shed any light on why this might be happening