Hello John,
There are 2 problems I see with the macro which are marked in red below. If the worksheet exists, you're setting the variable to nothing. When running the code manually, this sheet is probably already active and your next statement Cells(1, 1).Select works.
'Test to see if a Worksheet is open'.
On Error Resume Next
Set wsheet = Sheets("Tabelle1")
If wsheet Is Nothing Then 'Doesn't exist
MsgBox "Das Macro kann ohne Tabelle nicht ausgeführt werden!", vbCritical, "ExportPDF Error"
Set wsheet = Nothing
Exit Sub
Else 'Does exist
Set wsheet = Nothing
On Error GoTo 0
End If
'Reset cursor position on worksheet
Cells(1, 1).Select
Try making these changes and rerunning the macro...
'Test to see if a Worksheet is open'.
On Error Resume Next
Set wsheet = Sheets("Tabelle1")
If wsheet Is Nothing Then 'Doesn't exist
MsgBox "Das Macro kann ohne Tabelle nicht ausgeführt werden!", vbCritical, "ExportPDF Error"
Set wsheet = Nothing
Exit Sub
End If
On Error GoTo 0
'Reset cursor position on worksheet
wSheet.Cells(1, 1).Select
Sincerely,
Leith Ross
Bookmarks