+ Reply to Thread
Results 1 to 7 of 7

Creating new WB, then combining WS'

  1. #1
    Registered User
    Join Date
    07-05-2013
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    4

    Wink Creating new WB, then combining WS'

    Hello all,

    I got caught up in my code and was wondering if anyone could help me out.

    The code is supposed to create a new Workbook and then open worksheets within a folder with the same beginning and then save the workbook as the original save-as when it was created.

    I am able to create and save the new workbook, but unable to get CombineFormats(X) to work for me.

    Any suggestions are greatly appreciated

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating new WB, then combining WS'

    Stepping away from your code... what is the logic you're trying to accomplish?

    1) Create a new empty workbook
    2) Open all the workbooks in a given folder and copy each sheet into the new workbook as a new sheet of its own. So if there were 10 wbs with 3 sheets in each, the new workbook would have a total of 30 sheets in it when done.
    3) None of the original workbooks are changed


    Or

    1) Create a new empty workbook
    2) Open all the workbooks in a given folder and copy each sheet into the new workbook on the same sheet. So if there were 10 wbs with 3 sheets in each, the new workbook would have a single sheet with all the data from those 30 sheets stacked into a single reference sheet
    3) None of the original workbooks are changed


    Or something else?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    07-05-2013
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Creating new WB, then combining WS'

    Hey JBeaucaire,

    Option #1 is spot on.

    Here's the logic:
    1. I already have a portion of my script that cleans up .csv and formats them into columns, it saves them with default .csv name.
    2. This broken portion creates a new WorkBook that I will set as a variable between two names. It then finds all WS' matching X + "*" and adds them to the created Workbook and saves the file with save.

    Thanks for the looks

    My Background: Proficient in all web-designing languages, I can hang with Python. VB is new to me, this is my first macro.
    Last edited by arlu1201; 07-10-2013 at 02:25 AM. Reason: Do not quote whole posts.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating new WB, then combining WS'

    What is the value of X ? I don't see the variable referenced and filled earlier.

    If you put OPTION EXPLICIT at the top of your code modules, life gets easier in VBA, it will point out most syntax errors and spelling errors or missing variable declarations.

  5. #5
    Registered User
    Join Date
    07-05-2013
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Creating new WB, then combining WS'

    Quote Originally Posted by JBeaucaire View Post
    What is the value of X ? I don't see the variable referenced and filled earlier.

    If you put OPTION EXPLICIT at the top of your code modules, life gets easier in VBA, it will point out most syntax errors and spelling errors or missing variable declarations.
    Hey JBeaucaire,

    I'll post the full script when I get back in the office. I think that will clear up a lot of questions and such.

  6. #6
    Registered User
    Join Date
    07-05-2013
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Creating new WB, then combining WS'

    Here's the full code that I have created. I renamed some of the variables and such for privacy issues.

    The part that I am having a lot of trouble with is creating the new workbook, naming it and then adding sheets to the new workbook and saving it. I believe it has a lot to do with the new workbook that I am creating being active and being correctly called into "CombineFormats".

    Once again, help is greatly appreciated.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating new WB, then combining WS'

    Ok, here are my suggested edits so far. The problem with X in the Combine macro is that it hasn't been defined yet. I follow everything up until you CALL the CombineFormats and you use MasterWB1 as the variable to feed in as "X". That variable has not been declared yet and has no value.

    Please Login or Register  to view this content.

+ 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