+ Reply to Thread
Results 1 to 10 of 10

SelectedVBComponent - get parent workbook`

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    SelectedVBComponent - get parent workbook`

    i have the following:
    Set objMyVbComp = Application.VBE.SelectedVBComponent

    but if i check the ActiveWorkbook.Name, it is not the same.

    how can i get the parent workbook from a selectedvbcomponent?

    D

  2. #2
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: SelectedVBComponent - get parent workbook`

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    Last edited by JEC.; 01-24-2022 at 03:39 PM.

  3. #3
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: SelectedVBComponent - get parent workbook`

    JEC

    Thanks for the contribution but it is not working in my code. let me show you:

    Please Login or Register  to view this content.
    does that make sense?

  4. #4
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: SelectedVBComponent - get parent workbook`

    So where does it error? Did you already try the second option?

  5. #5
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: SelectedVBComponent - get parent workbook`

    a little more info

    I am running this from the immediate window.

    Please Login or Register  to view this content.
    i place my cursor in "CodeVerTest.xlsm" somewhere and go back to the immediate window and press enter.

    In your example, it returned "CodeVerData.xlsm" (which is the source of the procedure), which is wrong. It should have returned "CodeVerTest.xlsm".

    Does that help?

  6. #6
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: SelectedVBComponent - get parent workbook`

    is there a way to .Parent.Name up to the workbook name?

    A little help please.

    I did find that this works in that it gets the VBProject name. how can i use that to get the workbook name

    Please Login or Register  to view this content.
    Last edited by dmcgov; 01-25-2022 at 08:14 AM.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,263

    Re: SelectedVBComponent - get parent workbook`

    Filename is the property for the file name of the workbook with the specified project in it.
    Remember what the dormouse said
    Feed your head

  8. #8
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: SelectedVBComponent - get parent workbook`

    Application.VBE.ActiveVBProject.VBComponents.Parent.Filename is the solution

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,263

    Re: SelectedVBComponent - get parent workbook`

    Application.VBE.ActiveVBProject.VBComponents.Parent is just a very roundabout way of saying Application.VBE.ActiveVBProject

  10. #10
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: SelectedVBComponent - get parent workbook`

    ah, another tidbit. wonderful. will make that edit to my code. btw, got a question on how to implement this in a userform. will post to a new thread.

+ 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. [SOLVED] why do some UDFs refelct parent workbook?
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-23-2019, 01:43 PM
  2. [SOLVED] updating a parent workbook from a child workbook via Userform
    By smooth_beaker in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-01-2013, 08:39 AM
  3. [SOLVED] Making new worksheets in same workbook based on unique value in parent sheet
    By amlan009 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 06-10-2012, 10:21 PM
  4. Maintain Relative Link to Workbook in Parent Directory
    By SheeplessSleep in forum Excel General
    Replies: 4
    Last Post: 03-26-2012, 11:25 AM
  5. Finding a cell value in another workbook and copying parent value of it in same sheet
    By Pankaj Sonawane in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2010, 12:21 PM
  6. Mapping the call value with parent cell in another workbook
    By Pankaj Sonawane in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2010, 11:54 AM
  7. Open Workbook from Parent Dir
    By NTB in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-26-2010, 01:34 PM

Tags for this Thread

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