1

У меня есть макрос ниже, который копирует две ячейки на другую страницу, а затем печатает их на этикетке,

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

Может ли кто-нибудь помочь мне вернуться к исходному листу, который я включил при запуске макроса.

Спасибо

2 ответа2

1

Помните, откуда вы пришли:

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
0

Попробуйте вообще не использовать Selection . Это редко необходимо. Например (не отлажено):

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

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .