+ Reply to Thread
Results 1 to 11 of 11

Taking workbook names from cells and putting them in VBA

  1. #1
    Registered User
    Join Date
    11-23-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    15

    Taking workbook names from cells and putting them in VBA

    Hi Folks,

    I wonder if you can help me. My search-fu has failed to find an answer, so apologies if this has been done before.

    I'm setting up a small macro for a work colleage, which essentially exists to *** data from one spreadsheet and dump it in another. The example code is here, although WORKBOOKNAME is obviously not a real term:

    Please Login or Register  to view this content.
    The problem I'm having is with what I've defined as WORKBOOKNAME in the code above. The book name is going to change all the time. What I wanted was a code which would take the name I write in to cell H1 of "Alkyl", but any attempt I've made doesn't work and when it has worked I keep getting a prompt to update H1 values...


    Any thoughts? (I hope I've explained well enough)

    Best Regards,
    Michael

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,213

    Re: Taking workbook names from cells and putting them in VBA

    Be something like:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague, Czech rep.
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    138

    Re: Taking workbook names from cells and putting them in VBA

    Hi MichaelMcF,

    there is a function to get the file name if you implement it set a variable with it and input it in your code you´ll be fine whatever happens. Gimme a sec I´ll look where I have it dont remember the syntax by book....;-)

    Best regards

    Soul

    PS -- so you dont need to keep the cell reference for the book name

    EDIT:

    Please Login or Register  to view this content.
    there you go
    Last edited by SoulPrisoner; 09-25-2013 at 08:50 AM. Reason: Additional info

  4. #4
    Registered User
    Join Date
    11-23-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Taking workbook names from cells and putting them in VBA

    TMSHucks,

    Thanks very much. It's close to something I tried at and failed, and is also embarassingly simple! I feel like I've been over thinking things...

    Sorry for wasting your time with what was clearly a dumb question

  5. #5
    Registered User
    Join Date
    11-23-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Taking workbook names from cells and putting them in VBA

    SoulPrisoner,

    Thanks. TMShucks solution worked well enough for me. I might give your solution a try on another sheet though

    M

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,213

    Re: Taking workbook names from cells and putting them in VBA

    You're welcome.


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  7. #7
    Registered User
    Join Date
    11-23-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Taking workbook names from cells and putting them in VBA

    Hi Guys,

    Sorry, I thought the initial solution worked but I've come across a new issue. When I run the macro using TMSHucks' solution, I get a "Value Update" prompt. This prompt seems to be asking me to confirm the data file to use... so now my question splits into two parts:

    Is there any way to reference an external file - of variable name - without me having to confirm the file?

    What I want is the code to contain an external file name, which will be written in cell H1 in the workbook.

    OR

    Is there a better way to write this so that, instead of having the file name in a cell, the macro just asks me which file to use?

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,213

    Re: Taking workbook names from cells and putting them in VBA

    Generally speaking, if you drop a formula into cell with a reference to a workbook (or, I think, a worksheet), an the reference cannot be resolved, you will get a dialogue box displayed so that you can locate the file.

    So, first question: is the workbook open?

    Regards, TMS

  9. #9
    Registered User
    Join Date
    11-23-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Taking workbook names from cells and putting them in VBA

    No, I was hoping to lift directly from a closed workbook. If I have to live with the prompt, I'll live with it.

    Regards,
    M

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,213

    Re: Taking workbook names from cells and putting them in VBA

    If you're only accessing it to retrieve data, you could always open it in the background, Read-Only, using code before you drop the formula.


    Regards, TMS

  11. #11
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague, Czech rep.
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    138

    Re: Taking workbook names from cells and putting them in VBA

    Hi,

    I´m skipping the first part about the prompt, because I´m not exactly sure the conditions under which it occurs (and I think it shouldnt be happening with the solution I´ve proposed). But regarding the second part - getting data from another file; that is absolutely no problem, you can create a little userform with textbox where you fill in the path to the file and than all the magic can start...;-).

    Best regards

    Soul

    EDIT: and btw. some prompts you can bypass with this piece of coding:

    Please Login or Register  to view this content.
    but as i said above, I dont have a clear idea what issue you´re facing so it might be useless what I´ve just gave you. This helps for example against the dialog box which occurs when you´re openin xls (that tells you it old format or whatever it tells i know i just click OK and dont even read it)
    Last edited by SoulPrisoner; 09-27-2013 at 04:47 AM.

+ 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. taking data from multiple .csv files and putting them into one spreadsheet
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2012, 07:45 PM
  2. Taking mmm dd yyyy and putting them in order
    By humidbeing in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-30-2012, 04:35 AM
  3. [SOLVED] Taking Text From 1 End Of A String And Putting It On The Other
    By Tellm in forum Excel General
    Replies: 3
    Last Post: 07-04-2012, 08:20 AM
  4. Replies: 3
    Last Post: 04-18-2008, 05:42 PM
  5. putting worksheet names into cells
    By DAMman21 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-03-2005, 06:18 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