+ Reply to Thread
Results 1 to 10 of 10

Set X as Active Sheet

  1. #1
    Forum Contributor
    Join Date
    05-15-2015
    Location
    Orlando, FL
    MS-Off Ver
    Office Standard 2016
    Posts
    266

    Set X as Active Sheet

    Hi Everyone, trying to edit this code. Rather than having X as a set file, I'd like to change it to the Active Sheet when the macro was ran.

    Please Login or Register  to view this content.
    I thought I could simply do Set x = ActiveSheet, but this did not work. Any suggestions?

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,309

    Re: Set X as Active Sheet

    you have already got x declared as a workbook - was there no error message if you tried to run.

  3. #3
    Forum Contributor
    Join Date
    05-15-2015
    Location
    Orlando, FL
    MS-Off Ver
    Office Standard 2016
    Posts
    266

    Re: Set X as Active Sheet

    Quote Originally Posted by torachan View Post
    you have already got x declared as a workbook - was there no error message if you tried to run.
    My goal is to not declare it to a certain workbook as the file changes every time (e.g name changes every month). Thats why I need it to be just the active sheet that I loaded and then ran the macro.

  4. #4
    Forum Contributor
    Join Date
    05-15-2015
    Location
    Orlando, FL
    MS-Off Ver
    Office Standard 2016
    Posts
    266

    Re: Set X as Active Sheet

    Looks like 'Set x = Active.Workbook' solved the probelm.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Set X as Active Sheet


    Looks like useless to create a variable object on an already existing object, just using directly ActiveSheet rather than X …

  6. #6
    Forum Contributor
    Join Date
    05-15-2015
    Location
    Orlando, FL
    MS-Off Ver
    Office Standard 2016
    Posts
    266

    Re: Set X as Active Sheet

    Quote Originally Posted by Marc L View Post

    Looks like useless to create a variable object on an already existing object, just using directly ActiveSheet rather than X …
    Would you be able to give an example of the edit?

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow x or y ? Whatever …


    Just remove the Set x codeline then in the code replace any x by ActiveSheet …
    But according to your initial post the active worksheet is not in workbook x but in workbook y !

    Another way to go rather than creating object variable is to use a With block like you can see within VBA help.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Maybe …


    Correction : use set x = ActiveSheet if you wanna save the active sheet before to open the workbook y …

  9. #9
    Forum Contributor
    Join Date
    05-15-2015
    Location
    Orlando, FL
    MS-Off Ver
    Office Standard 2016
    Posts
    266

    Re: Maybe …

    Quote Originally Posted by Marc L View Post

    Correction : use set x = ActiveSheet if you wanna save the active sheet before to open the workbook y …
    That doesn't seem to be working for me. just errors on the Activesheet line.

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow


    Variable must be defined obviously as Worksheet rather than Workbook if it's for the active sheet rather than the active workbook …

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to go back to the last active sheet and hide the active sheet
    By yatahaze in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2014, 08:18 AM
  2. Replies: 1
    Last Post: 07-07-2014, 09:19 AM
  3. [SOLVED] save active sheet in new workbook, naming it as cell value of active sheet
    By arkharova.s in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-18-2014, 06:16 AM
  4. Replies: 1
    Last Post: 01-04-2014, 06:37 PM
  5. Macro to Print active sheet as PDF to Active workbook and customize name
    By Scott Taylor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-17-2012, 08:52 PM
  6. how can worksheet_activate event of active sheet work of active workbook
    By tahir mahmood in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2011, 08:19 AM
  7. Copy from active sheet and paste into new sheet using info from cell in active
    By Ingve in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2006, 06:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1