Excel VBA-第一张图片在导出前不会加载

我有一个文件夹与几个Excel工作簿,我需要出口到PDF格式。 每个工作簿的每张纸上都有一个徽标(.bmp)。 当我使用下面的代码时,只有第一页上的pdf都丢失了标识(它有一个灰色的占位符)。 其余的页面有标志。

我的代码:

Option Explicit Sub dsPdf() Dim path As String Dim wbName As String Dim tWb As Workbook Dim t As Single path = ThisWorkbook.path wbName = Dir(path & "\*.xlsx") Application.ScreenUpdating = True Do While wbName <> "" Set tWb = Workbooks.Open(path & "\" & wbName) tWb.Sheets(Array(1, 2, 3)).Select DoEvents ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ path & "\" & Left(wbName, Len(wbName) - 4) & "pdf", _ Quality:=xlQualityStandard, IncludeDocProperties:=True, _ IgnorePrintAreas:=False, OpenAfterPublish:=False tWb.Close False wbName = Dir Loop End Sub 

我已经尝试使用ActiveSheet.RefreshAllDoEvents ,以及添加一个Timer / Do While循环。 当我在出口声明之前放置Stop ,第一张表格正确显示徽标。 但是,当我把Aplication.Wait(Now...的标志不显示。

有任何想法吗? 谢谢

试试这个 – 我避免使用。select,因为(我不确定),但我认为这可能会导致一些问题。

 Sub dsPdf_NoSelect() Dim path As String Dim wbName As String Dim tWb As Workbook Dim t As Single Dim i As Long path = ThisWorkbook.path wbName = Dir(path & "\*.xlsx") Application.ScreenUpdating = True Do While wbName <> "" Set tWb = Workbooks.Open(path & "\" & wbName) For i = 1 To 3 tWb.Sheets(i).ExportAsFixedFormat Type:=xlTypePDF, Filename:=path & "\" & Left(wbName, Len(wbName) - 4) & "pdf", _ Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False Next i tWb.Close False wbName = Dir Loop End Sub