Share via

create a non-sheet specific macro

Ken Smith 46 Reputation points
2021-12-07T19:44:23.923+00:00

how do I create a macro that will work with any worksheet I choose, within the same workbook? i.e. a PRINT macro whereby I select certain cells in a worksheet to be printed.

Developer technologies | Visual Basic for Applications
0 comments No comments

2 answers

Sort by: Most helpful
  1. Ken Smith 46 Reputation points
    2021-12-08T16:24:07.11+00:00

    Not familiar with ActiveSheet. You are talking to a novice with VBA, here. Will check out ActiveSheet.

    Was this answer helpful?

    0 comments No comments

  2. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2021-12-08T01:48:11.537+00:00

    One way would be to create a procedure that takes a Worksheet as an argument:
    public sub DoSomePrinting(byref ws as Excel.Worksheet)
    'do some printing with this ws data
    end sub

    Rather than creating such procedure and passing in a Worksheet object, you can also use ActiveSheet to refer to the current one.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.