vendredi 21 décembre 2018

Using a cell reference cycle (of a range) to open and print excel workbooks

I'm looking to go through a range of cells and use each value within the cells to open a workbook, to then print out the first worksheet, close the workbook, and then cycle to the next value until the range hits a blank cell.

This is what I have so far:

Sub Test()

Dim varCellvalue As Long Dim rng As Range, cell As Range Dim wb As Long Set rng = Range("A1:A20")

For Each cell In rng

If Not cell = "" Then

varCellvalue = Range(cell).Value

Workbooks.Open "G:_QA\Excel Workspace\Projects\Auto-print Processing Forms\Printouts\" & varCellvalue & ".xls"

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _ IgnorePrintAreas:=False

Workbooks(varCellvalue).Close SaveChanges:=False

On Error Resume Next

End If

Next cell

End Sub

I have a workbook that processes data of another imported sheet that gets updated every day. So far I'm to the point of having all the information I need to then cycle through the generated list and use the resulting cell values to then open and print the worksheets I need.

Aucun commentaire:

Enregistrer un commentaire