对象'_worksheet'的方法'ExportAsFixedFormat'失败

时间:2016-05-23 11:21:15

标签: excel vba excel-vba

以下是将所有Excel表格导出为PDF的代码:

Sub printing()

Dim i As Integer, wkb As String, head As String, nm As String
Dim ws As Worksheet

Application.ScreenUpdating = False

'get folder path
wkb = InputBox("Enter folder path:", , ActiveWorkbook.Path)
If Right(wkb, 1) <> Application.PathSeparator Then wkb = wkb & Application.PathSeparator

'head of file name
head = InputBox("Enter head of file name", , "Test")

Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
'ActiveWorkbook.Sheets.Count

    If ws.Visible = True Then
        ws.Select
        nm = ws.Range("A1")
        If nm <> "" Then
            'save
            ActiveSheet.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                FileName:=wkb & head & nm & ".pdf", _
                Quality:=xlQualityStandard, _
                IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, _
                OpenAfterPublish:=False
        End If

        Application.DisplayAlerts = False
    End If
Next

Application.DisplayAlerts = True
Application.ScreenUpdating = True

MsgBox "Done"

End Sub

我在我的Mac和我朋友的Mac上运行这个宏,但是我的Mac通过了,我的朋友的mac没有通过并发生错误:

  

运行时错误'1004':

     

对象'_worksheet'的方法'ExportAsFixedFormat'失败

你能告诉我解决方法吗?

感谢。

0 个答案:

没有答案