+ Reply to Thread
Results 1 to 10 of 10

If workbook name contains string then run macro

  1. #1
    Registered User
    Join Date
    05-05-2016
    Location
    Melbourne, Australia
    MS-Off Ver
    Office 365
    Posts
    26

    If workbook name contains string then run macro

    Hi champs,

    I'm extracting reports on which I run a macro; these files always start with getjobid and I currently have to run the macro manually once the file is loaded.
    Hence, in order to speed up the process I have been working on a code to check the name of all workbooks that open up, and run this macro if the name of the workbook start with "getjobid", however I am getting a debug with my code and couldn't find a workaround anywhere, hence my post.

    I have placed my code below under Thisworkbook within my PERSONAL.XLSB project:

    Please Login or Register  to view this content.
    It seemed pretty straightforward to me but won't work.

    I have tested it by entering the below line which said getjobid as expected, however it fails within the code above.

    Please Login or Register  to view this content.
    Appreciate any help.
    Cheers,
    Fabien

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: If workbook name contains string then run macro

    There's extra space at the text "getjobid " .. Try removing that extra space
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    05-05-2016
    Location
    Melbourne, Australia
    MS-Off Ver
    Office 365
    Posts
    26

    Re: If workbook name contains string then run macro

    Hi,
    Thanks for your quick response.
    Unfortunately that didn't do the trick. :-(

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: If workbook name contains string then run macro

    Quote Originally Posted by fabien1 View Post
    I have placed my code below under Thisworkbook within my PERSONAL.XLSB project:
    Why don't you use the code for the active workbook module?

  5. #5
    Registered User
    Join Date
    05-05-2016
    Location
    Melbourne, Australia
    MS-Off Ver
    Office 365
    Posts
    26

    Re: If workbook name contains string then run macro

    Because the active workbook changes everytime i open this getjobid file.

    Does it make sense?

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: If workbook name contains string then run macro

    But I don't think in this case the code would be put in thisworkbook module for PERSONAL.XLSB ...

  7. #7
    Registered User
    Join Date
    05-05-2016
    Location
    Melbourne, Australia
    MS-Off Ver
    Office 365
    Posts
    26

    Re: If workbook name contains string then run macro

    Where do you suggest I place the code?

    I have tried placing it into the 'Sheet1' as well as 'Module1' and it didn't run.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: If workbook name contains string then run macro

    Hi,

    If you want to check any workbook that opens, you need an application event. See Chip Pearson's site.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  9. #9
    Registered User
    Join Date
    05-05-2016
    Location
    Melbourne, Australia
    MS-Off Ver
    Office 365
    Posts
    26

    Re: If workbook name contains string then run macro

    Ok thanks, I got it working.
    For those who might be interested, find the code below:

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: If workbook name contains string then run macro

    Great. Glad you have solved it

+ 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. VBA Control other workbook and throw string to other workbook
    By nanutum in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2016, 11:37 AM
  2. [SOLVED] Macro to change 1) part of string, 2) the order of characters inside a string, 3) format
    By Karl Gustaf Karsten in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2015, 11:51 AM
  3. [SOLVED] Macro to create a new line within a text string if specific characters appear mid-string
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2014, 11:32 AM
  4. [SOLVED] Delete workbook if contains x string
    By calvinle in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-20-2014, 02:10 AM
  5. [SOLVED] Formula or Macro, match string,from 1 cell to a column,String use dash
    By david gonzalez in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-07-2013, 06:03 PM
  6. String and Value workbook reference
    By jsp_1951 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-16-2013, 10:31 PM
  7. Replies: 2
    Last Post: 01-02-2013, 08:35 AM

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