I'm a real noob when it comes to programming but I know there has to be a more effcient way to write the program I did below.
Is there a way to use an array, or while statement or something?
Bisically, I'm opeing an excel documents and printing various worksheets in that document. Can I somehow loop thru the select and print statements instead of typing our each statement for all the sheets?
Code:Sub Main() Dim xlfile As Excel.Application Set xlfile = New Excel.Application xlfile.Application.Visible = True '--------------------------------- '----------OPEN DOCUMENT---------- '--------------------------------- xlfile.Workbooks.Open "\\roi-primary\data\Engineering\San Antonio\Forms & Procedures\C9 Tooling Change Log.xls", UpdateLinks:=1, ReadOnly:=True, Notify:=False '--------------------------------- '---------------10A--------------- '--------------------------------- xlfile.Worksheets("Op10 Tool Change Log").Select xlfile.ActiveWindow.SelectedSheets.PrintOut Copies:=6 '--------------------------------- '---------------20A--------------- '--------------------------------- xlfile.Worksheets("Op20 Tool Change Log").Select xlfile.ActiveWindow.SelectedSheets.PrintOut Copies:=6 '--------------------------------- '---------------30A--------------- '--------------------------------- xlfile.Worksheets("Op30 Tool Change Log").Select xlfile.ActiveWindow.SelectedSheets.PrintOut Copies:=6 '--------------------------------- '---------------40A--------------- '--------------------------------- xlfile.Worksheets("Op40 Tool Change Log").Select xlfile.ActiveWindow.SelectedSheets.PrintOut Copies:=6 '--------------------------------- '---------------60A--------------- '--------------------------------- xlfile.Worksheets("Op60 Tool Change Log").Select xlfile.ActiveWindow.SelectedSheets.PrintOut Copies:=6 '--------------------------------- '---------------70A--------------- '--------------------------------- xlfile.Worksheets("Op70 Tool Change Log").Select xlfile.ActiveWindow.SelectedSheets.PrintOut Copies:=6 '--------------------------------- '---------------80A--------------- '--------------------------------- xlfile.Worksheets("Op70 Tool Change Log").Select xlfile.ActiveWindow.SelectedSheets.PrintOut Copies:=6 '--------------------------------- '---------------90A--------------- '--------------------------------- xlfile.Worksheets("Op70 Tool Change Log").Select xlfile.ActiveWindow.SelectedSheets.PrintOut Copies:=6 '--------------------------------- '---------CLOSE WORKBOOK---------- '--------------------------------- xlfile.Application.DisplayAlerts = False xlfile.Workbooks.Close '--------------------------------- '----------CLOSE EXCEL------------ '--------------------------------- xlfile.Application.Quit End Sub




Reply With Quote