Retornar à página selecionada após a execução da macro

1

Eu tenho a macro abaixo que copia duas células em uma página diferente e as imprime em um rótulo

Sub Tag_75()
ActiveCell.Resize(1, 1).Copy Worksheets("Sheet1").Range("A1")

ActiveCell.Offset(, 1).Resize(1, 1).Copy Worksheets("Sheet1").Range("A2")

'Worksheet("Sheet1").Range("A1:A2").Borders.LineStyle = xlNone
Sheets("Sheet1").Select
    Range("A1:A2").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

Worksheets("Sheet1").Range("A2").WrapText = True
Worksheets("Sheet1").Range("A1:A2").Font.Size = 22
Worksheets("Sheet1").Range("A1:A2").ShrinkToFit = True

Dim STDprinter As String

STDprinter = Application.ActivePrinter
'Application.ActivePrinter = "\SBS2011\Xerox WorkCentre 7830 on Ne06:"
Application.ActivePrinter = "\JCSP55J\DYMO LabelWriter 450 (Copy 2) on Ne05:"
ActiveSheet.PrintOut
Application.ActivePrinter = STDprinter

End Sub

Alguém pode me ajudar a voltar para a folha original quando estiver executando a macro.

Obrigado

    
por Ryanagray 05.09.2016 / 17:13

2 respostas

1

Lembre-se de onde você veio:

Sub Tag_75()
dim sh as worksheet
Set sh = Activesheet

ActiveCell.Resize(1, 1).Copy Worksheets("Sheet1").Range("A1")

ActiveCell.Offset(, 1).Resize(1, 1).Copy Worksheets("Sheet1").Range("A2")

'Worksheet("Sheet1").Range("A1:A2").Borders.LineStyle = xlNone
Sheets("Sheet1").Select
    Range("A1:A2").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

Worksheets("Sheet1").Range("A2").WrapText = True
Worksheets("Sheet1").Range("A1:A2").Font.Size = 22
Worksheets("Sheet1").Range("A1:A2").ShrinkToFit = True

Dim STDprinter As String

STDprinter = Application.ActivePrinter
'Application.ActivePrinter = "\SBS2011\Xerox WorkCentre 7830 on Ne06:"
Application.ActivePrinter = "\JCSP55J\DYMO LabelWriter 450 (Copy 2) on Ne05:"
ActiveSheet.PrintOut
Application.ActivePrinter = STDprinter

sh.Activate
End Sub
    
por 05.09.2016 / 19:08
0

Tente não usar Selection . Isso raramente é necessário. Por exemplo (não depurado):

Sub Tag_75()
ActiveCell.Resize(1, 1).Copy Worksheets("Sheet1").Range("A1")

ActiveCell.Offset(, 1).Resize(1, 1).Copy Worksheets("Sheet1").Range("A2")

'Worksheet("Sheet1").Range("A1:A2").Borders.LineStyle = xlNone
with Sheets("Sheet1").Range("A1:A2")
    .Borders(xlDiagonalDown).LineStyle = xlNone
    .Borders(xlDiagonalUp).LineStyle = xlNone
    .Borders(xlEdgeLeft).LineStyle = xlNone
    .Borders(xlEdgeTop).LineStyle = xlNone
    .Borders(xlEdgeBottom).LineStyle = xlNone
    .Borders(xlEdgeRight).LineStyle = xlNone
    .Borders(xlInsideVertical).LineStyle = xlNone
    .Borders(xlInsideHorizontal).LineStyle = xlNone
End With

Worksheets("Sheet1").Range("A2").WrapText = True
Worksheets("Sheet1").Range("A1:A2").Font.Size = 22
Worksheets("Sheet1").Range("A1:A2").ShrinkToFit = True

Dim STDprinter As String

STDprinter = Application.ActivePrinter
'Application.ActivePrinter = "\SBS2011\Xerox WorkCentre 7830 on Ne06:"
Application.ActivePrinter = "\JCSP55J\DYMO LabelWriter 450 (Copy 2) on Ne05:"
ActiveSheet.PrintOut
Application.ActivePrinter = STDprinter

End Sub
    
por 05.09.2016 / 20:56