Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:08:14+00:00 2026-06-06T19:08:14+00:00

How can i refer to the object i use inside With if i want

  • 0

How can i refer to the object i use inside With if i want the object itself, not its properties / methods?

With ThisWorkbook.Sheets("MySheet")
    Call MySub(ThisWorkbook.Sheets("MySheet")) ' works OK, but duplicated
    Call MySub(this) ' does not works
    .Range(...).Value2 = 1
    ...
End With

+ what is the correct terminology here? i don’t even know how to compose a google query for this and get some usefull results (since with is a common word)…


UPDATE: to clarify, i was thinking in terms of a handle like with ... as handle from python syntax, not about object-oriented this keyword

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:08:15+00:00Added an answer on June 6, 2026 at 7:08 pm

    How about by not using with in the first place? It makes your code much more readable, uses no more memory (as the with statement has to allocate a temporary variable anyway), and is less confusing.

    Dim WS as WorkSheet
    WS = ThisWorkBook.Sheets("MySheet")
    Call vymaz_obrazky(WS)
    WS.Range(...).Value2 = 1
    

    In the code above, the total cost is one additional line of code (the DIM statement), and 9 less keystrokes overall. (The DIM statement is 19 keystrokes, changing to WS in the three lines is 6 keystrokes, but you’ve saved the with (4) and duplication (30), saving about 9 keystrokes.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make a ForeignKey refer back to the object itself? I'm trying
When I want to find a child of an object I can use children()
In some contexts, we can use an array($this, 'variable') syntax, to refer to object
Snow Leopard introduced many new methods to use NSURL objects to refer to files,
How can I refer to the control while I am inside a control's method
I want to use values of the calling object within the jquery code block,
I know I can refer in replacement to dynamic parts of the term in
please let me know a java multithread application which i can refer ( source
In my app, I have a facebook field that can refer to a facebook
I am using asp.net forms authentication, membership provider and role provider. You can refer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.