【问题标题】:How to add a loop into macro如何在宏中添加循环
【发布时间】:2016-10-27 15:07:29
【问题描述】:

我需要在我的代码中添加第二个循环。目前,它通过一个列表进行打印(在名为“Dealer”的工作表中并从“B2”开始,并为列表中的每个项目打印不同的 PDF。

我需要的第二个循环必须是长相同的行。它必须通过一个单独的工作表中的语言列表,并重新打印具有多个语言的每个 PDF。

对此的任何帮助将不胜感激。我的代码如下......

Dim PathString As String

Sub Print_************_2_ImpactValidationReport()

Application.ScreenUpdating = False

Sheets("Dealer").Select
Range("B2").Select


    While Not ActiveCell.Value = Empty

    Sheets("ImpactValidationReport").Range("AO1").Value = ActiveCell.Value
    Sheets("ImpactValidationReport").Select
    'Call ChangeGraphAxis
    Range("A4").Select
    Sheets("ImpactValidationReport").Select
    Application.StatusBar = "Executing - Please be patient..."
    Call Print_To_File4(Sheets("ImpactValidationReport").Range("AO1").Value)
    Application.StatusBar = False
    Sheets("Dealer").Select
    ActiveCell.Offset(1, 0).Select

Wend

Sheets("ImpactValidationReport").Select
Application.ScreenUpdating = True

Sheets("ImpactValidationReport").Select
Range("A3").Select

MsgBox "All Completed, Please check Files!"

End Sub


Function Print_To_File4(Dealer As String)

'PathString = ***************************\Reporting\DistrictReports\2_ImpactValidationReport" & DealerGroup & ".pdf"
'ActiveWindow.SelectedSheets.PrintOut Copies:=1, PrintToFile:=True, PrToFileName:=PathString

CurrentDir = ActiveWorkbook.Path
Application.DisplayAlerts = False

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    CurrentDir & "\Reporting\DistrictReports\2_ImpactValidationReport\District_Action_Report_" & Dealer & "_2_ImpactValidationReport_" & Format(Now, "dd-mm-yy") _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False

Application.DisplayAlerts = True

End Function

【问题讨论】:

    标签: vba excel macros


    【解决方案1】:

    如果我理解正确,您需要以下结构(我使用 ij 作为增量来控制循环):

    i = 1
    While Not cells(i,1) = Empty
        'check all items
        j=1
        while not sheets("language").cells(j,1) = Empty
            'check all languages for the item
            j=j+1
        wend
    
        i=i+1
    wend
    

    【讨论】:

      猜你喜欢
      • 2019-03-29
      • 2014-03-07
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      相关资源
      最近更新 更多