PDA

View Full Version : Error 400



heroofgoodwi
10-23-2017, 03:01 AM
hey guys, I have been writing a piece of code and for some reason it keeps throwing up an error 400 and I for the life of me cannot figure out why it is doing that. I think it may have something to do with the SelectAFolder2 line but I am not sure so any help would be appreciated.




Sub saveCopies()
Dim x As Integer 'x = workstream list
Dim counter As Integer 'counter = counter for workstreams
Dim wb As Workbook 'define active workbook
Dim reportws As Worksheet ' set report ws

Set wb = ActiveWorkbook 'activate workbook
Set reportws = Sheets("Report") 'define report sheet
counter = 0 'set counter to zero
reportws.Select 'select report worksheet
DestFolder = SelectAFolder2
For x = 1 To 25 ' 1 for each workstream of summary
Application.ScreenUpdating = False 'turn off screen updating to speed up code
counter = counter + 1
Cells(1, 1).Value = counter
Application.StatusBar = "Producing report " & counter 'set up status bar to show progress report
Application.ScreenUpdating = True 'Turn on screen updating to snapshot report

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=DestFolder & Application.PathSeparator & Range("D26").Value, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Next x 'next workstream
Application.StatusBar = False 'Clear status bar
MsgBox "Reports have been produced" 'notify user that program has finished.
End Sub

'sub function to select folder location. Linked to Dynamic title cell

Function SelectAFolder2()
With Application.FileDialog(msoFileDialogFolderPicker)
'.InitialFileName = ??
.Title = "Select a Folder to save to"
.AllowMultiSelect = False
If .Show = -1 Then SelectAFolder = .SelectedItems(1)
End With
End Function

Jan Karel Pieterse
10-23-2017, 04:52 AM
What line is yellow when you click Debug on that error?