+ Reply to Thread
Results 1 to 11 of 11

deleting worksheets from a file which has macros in it........does not work.

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    deleting worksheets from a file which has macros in it........does not work.

    Hi,

    I have this macro and i save a copy of this file (along with all its worksheets) to a specified location.

    I do this so that i can then reopen the file and use all of the VBA code that is located in the "ThisWorkBook" module and some of the VBA code in one of the worksheet modules.

    So i open this copied file......i begin to delete the worksheets i dont need........and the macro will delete the first worksheet but then it will just STOP.



    NOTE: iF I run the macro such that you have the VBA code open then when i open the copied file i get a question about "enabling" the macros. When ever i get asked this question.....the macro will run as its supposed to ......

    I am enclosing the macro. When you click launch what is supposed to happen is that all of the sheets in the workbook except the worksheet named "Prompt" and the worksheet named "Four col sht" are to be deteled.........but this does not happen.

    It will only happen provided you have the VBA code open and you get a question asking about enabling / disabling the macro for the "copied" file.

    Any ideas?
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: deleting worksheets from a file which has macros in it........does not work.

    anyone have any ideas?

    Also, if someone can just run it and verify that they get the same result i would appreciate it.

    note: if you do run it you need to change the "path" to something that is valid on your machine.

    i just dont get this at all......after i open the file and then delete teh first sheet in the copied workbook the macro just stops.

    very very strange.

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: deleting worksheets from a file which has macros in it........does not work.

    just curious why no has responded on this.......did i post it incorrectly or did i confuse everyone?

    i am really lost on this one........at my limit actually...........could really use some help

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: deleting worksheets from a file which has macros in it........does not work.

    do you think that because the orignal file has a macro module and i am making a copy and then opening the copy which would also now have a macro module ........i assume on opening via vba that the macros are disabled in this new file......but would this cause a problem.


    should i change the title of this thread?

    can someone help?

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: deleting worksheets from a file which has macros in it........does not work.

    Hello Welchs101,

    I wrote a macro to make a copy of the workbook with the sheets and code you want. The new workbook stays open after it is created. You can easily write a macro to save this where you want. Copy this code into into a new VBA module in your workbook.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: deleting worksheets from a file which has macros in it........does not work.

    thanks Leith. I had all but given up on this. Thanks a lot.


    I see some very interesting things in the code......i will have to review them..........opportunity to learn. I think i know whats goign on.

    thanks again!!!!!!!!!!!!!!!!!!

  7. #7
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: deleting worksheets from a file which has macros in it........does not work.

    oh, just wanted to add it works great.

    To get it to work i did have to change a setting in the "trust center". I had to place a tick mark beside
    "Trust access to the VBA project object model".

    Once i did that it worked fine. If i did not do that then i got a run time error.

    "Programmtic access to the visual basic project is not trusted."

  8. #8
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: deleting worksheets from a file which has macros in it........does not work.

    For those interested in what this is i looked it up:

    Trust access to the VBA project object model:
    This setting is for developers and is used to deliberately lock out or allow programmatic access to the VBA object model from any Automation client. In other words, it provides a security option for code that is written to automate an Office program and programmatically manipulate the Microsoft Visual Basic for Applications (VBA) environment and object model. This is a per user and per application setting, and denies access by default. This security option makes it more difficult for unauthorized programs to build "self-replicating" code that can harm end-user systems. For any Automation client to be able to access the VBA object model programmatically, the user running the code must explicitly grant access. To turn on access, select the check box.


    FYI: So if someone else wants to run my macro they will have to have this turned on.

  9. #9
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: deleting worksheets from a file which has macros in it........does not work.

    Leith,

    Your code is very well written and easy to understand..well for the most part. there are few things i need to look up but i get what you're doing even though i may not understand some of the commands.....nicely written.

  10. #10
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: deleting worksheets from a file which has macros in it........does not work.

    hi all, i did want to let you know i found a slight bug in the code.

    If i ran the code for the first time i would get an error that could only be caused by transferring vba code from "thisworkbook" section to a workbook that should not have this information transferred to it.

    So i realized that i needed to be more specific in "exactly" specifying what workbooks are doing what. See code below.......note the code which does not specify the exact workbook references is commented out........



    Please Login or Register  to view this content.

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: deleting worksheets from a file which has macros in it........does not work.

    Hello Welchs101,

    Sorry about not mentioning making the change to the Trust Center settings. I assumed with your experience you would not need to be reminded. That was a bad call on my part because it deals with the VBIDE (Visual Basic Integrated Development Environment) and not just VBA macros.

    Despite that, you managed to figure it out with no problem. Excellent work! Not many people would have figured that out on their own. From your comments, it looks like I did my job correctly. You were able to read the code, identify its functional parts, and modify it as needed.

    I am going to mark this post as solved. If have any questions about the code, I will happy to answer them.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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