+ Reply to Thread
Results 1 to 29 of 29

Link Parts Of Workbook Filename To Cells

  1. #1
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Link Parts Of Workbook Filename To Cells

    Okay, here's a weird one:

    It would speed things up, as well as solve accuracy issues if I could have certain cells in my workbook linked to its actual filename. I attached my example workbook to help clarify:

    The Data Entry Page is the sheet I'll need to modify. This workbook is a blank, which gets 'saved as' to a name like '123456-7 REV08' So then, it would be great if upon opening it, Cell B9:G9 would display the group of digits before the 'space', in this example '123456-7', and Cell B11:C11 would display the group after - '08'.

    Can this be done?!
    Attached Files Attached Files

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

    Re: Link Parts Of Workbook Filename To Cells

    Define a name called FileName (via the Name manager on the Formulas tab) using the formula:
    =MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

    then in your cells use:
    =TRIM(left(FileName, SEARCH("REV", Filename)-1))
    and
    =MID(Filename, search("REV",filename)+3,255)
    respectively.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Hey, this looks hopeful! Thanks so much! Here's some issues though:

    Cell B11:C11 shows the extension of the file name too - '08.xlsm' where it should only show '08'.

    Could these formulas be moved into the macro for this sheet? I'd like the option to be there for someone to change the values in those cells and be warned that it doesn't match the file name. And is there a way to keep them from displaying anything if the filename is exactly this: 'Blank Inspection Reports & C of Cs.xlsm'?
    Last edited by swordswinger710; 02-24-2010 at 02:54 PM.

  4. #4
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Any thoughts on this?

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

    Re: Link Parts Of Workbook Filename To Cells

    Which macro are you talking about specifically?

  6. #6
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Maybe 'macro' isn't the right term, but I'm referring to the VBA code for the Data Entry Sheet..

  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,331

    Re: Link Parts Of Workbook Filename To Cells

    I'm still not clear. When do you want these cells populated (i.e. what do you want to trigger the code that will populate them) and what exactly do you want to happen if the code is triggered and the cells already have other values in them? Also, do I understand that you want the code to monitor those cells for changes too? Should the user be allowed to override the values you have specified?

  8. #8
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Alright, let me try to be clearer!

    This is the way I'd like it to work:
    The user opens the 'Blank Inspection Reports & C of Cs' workbook. The Data Entry Page is empty. The workbook gets saved as a part name and rev, such as '123456-7 REV08'. Now, Cell B9:G9 displays '123456-7' and Cell B11:C11 displays '08'. (The ideal time for those two cells to display their information would be right after the user enters a value in the cells above them, actually.) If this workbook gets saved as another part number, then the numbers in those cells should immediately reflect the new filename, replacing whatever was in them before.

    And the user shouldn't be able to change the values to anything but the filename, but I'd like the cells to be 'editable' - which is why I thought the code should be on the VBA sheet rather than in the actual cells.. For example, sometimes a Rev will change, and I'd like the user to be able to change the value in Cell B11:C11, and upon hitting Enter/etc. he should get an error message stating that the filename should be changed in order to change that value, and the rev should switch back to what it was.

    If I'm still not clear enough on anything, just give me a yell.. and thanks so much!

    Oh! One more thing - it would be good if the user would get an error message if he tries to enter information before saving the workbook as a part number and rev first...
    Last edited by swordswinger710; 02-25-2010 at 10:04 AM.

  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,331

    Re: Link Parts Of Workbook Filename To Cells

    Quote Originally Posted by Juda View Post
    And the user shouldn't be able to change the values to anything but the filename, but I'd like the cells to be 'editable' - which is why I thought the code should be on the VBA sheet rather than in the actual cells.. For example, sometimes a Rev will change, and I'd like the user to be able to change the value in Cell B11:C11, and upon hitting Enter/etc. he should get an error message stating that the filename should be changed in order to change that value, and the rev should switch back to what it was.
    I don't see why you would want those cells to be editable if you won't let them be changed?!

    It seems to me that the simplest thing would be to trap the save event and have the cells populated automatically then?

  10. #10
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Well, it's a bit hard to explain - I guess I just want the user to be aware of the way the value in those cells are linked with the filename... and I don't want them to be able to delete the code - like they could if it was right in the cell.

    And I'm not sure I understood your last sentence there.. but whatever works best for you should be okay! Thanks again!

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

    Re: Link Parts Of Workbook Filename To Cells

    Can you test this for the save code? It's a bit rough but should work, I think. Once it's OK I'll add in the other check.
    Attached Files Attached Files

  12. #12
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Sweet! The saving part works great! The only thing I noticed was that there's an extra space after the part number (but who really cares) and the values show up right after saving instead of after data is entered in the cell above each of them - but this works too. I love it! Thank you!

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

    Re: Link Parts Of Workbook Filename To Cells

    For the file check when entering data, add this to the start of the worksheet_Change code for the data sheet:
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Okay, I did that, but I'm getting a

    Compile error: Invalid outside procedure

    with 'This Workbook' highlighted... am I missing something?

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

    Re: Link Parts Of Workbook Filename To Cells

    That code needs to go after the:
    Please Login or Register  to view this content.
    line in the worksheet's code module (right-click the sheet tab and choose 'View Code')

  16. #16
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Okay - that's more like it! Wonderful! Thank you! The only issue I have yet, is that a user can change the values in those cells without being notified about it... could that be worked in there somehow?

  17. #17
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    So what do you think?

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

    Re: Link Parts Of Workbook Filename To Cells

    Another addition to the Change Event - this goes above the last snippet:
    Please Login or Register  to view this content.

  19. #19
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Wow! That works! Almost...

    When I save the blank as a part number and rev, then add additional data to the workbook, upon closing it I get the window that asks if I want to save the changes. I click yes. Then it asks me again. So I click yes. Haha, I could go on for a long time...

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

    Re: Link Parts Of Workbook Filename To Cells

    Can you post the current version?

  21. #21
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Absolutely! Here is what we have so far... Thanks again for all your time!
    Attached Files Attached Files

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

    Re: Link Parts Of Workbook Filename To Cells

    Add this to the ThisWorkbook module:
    Please Login or Register  to view this content.

  23. #23
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Hmm.. now when I close the workbook after making changes, I first get your window asking 'Do you wish to save the workbook before closing?' and I say yes, then I get the default one asking me the same thing, and I can still click Yes a hundred times in a row without it closing!

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

    Re: Link Parts Of Workbook Filename To Cells

    That's odd - it was working in my tests. I won't be able to look at it until next week now, I'm afraid.

  25. #25
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    That's okay, I'll wait! Maybe you should reattach the workbook that was working for you - in case I'm doing something wrong...

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

    Re: Link Parts Of Workbook Filename To Cells

    Unfortunately, it's at work and I'm on my way home...

  27. #27
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Okay, well don't worry about it.. it's not that urgent, thanks again! And have a great weekend!

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

    Re: Link Parts Of Workbook Filename To Cells

    I seem to have somehow missed a bit when posting. It should be:
    Please Login or Register  to view this content.

  29. #29
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Link Parts Of Workbook Filename To Cells

    Hello! Hey, thanks so much for that! It seems to work well!

    I do have a few more questions, nothing really important, just little adjustments we could do...

    I tried to find the code where it selects the digits before the REV, so I could remove that space it puts in there after the number, but I couldn't find it! Also, if either of the two cells are clicked in and not modified, the user still gets an error message saying not to change it - I would be nicer if the error would only appear if the value was actually changed.

    Again, only trifles - but I thought I'd ask. And thanks again!

+ 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