+ Reply to Thread
Results 1 to 6 of 6

Run macro from newly created workbook

Hybrid View

jaryszek Run macro from newly created... 06-15-2018, 05:51 AM
kasan Re: Run macro from newly... 06-15-2018, 06:38 AM
jaryszek Re: Run macro from newly... 06-15-2018, 08:06 AM
kasan Re: Run macro from newly... 06-15-2018, 08:29 AM
jindon Re: Run macro from newly... 06-15-2018, 08:36 AM
jaryszek Re: Run macro from newly... 06-15-2018, 08:54 AM
  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,945

    Run macro from newly created workbook

    Hi Guys,

    i am writing SQLs using ODBC connection.
    And to avoid leak memorys the best is to connect to another workbook and use it as source.

    1. I have a current workbook and i am runing macro from this.
    2. Macro is creating new workbook and catching differences between variables.
    3. Macro will be also catching differences between tables using SQL and odbc.

    Problem is that when i am creating new workbook i would like to close current one (with macro) and run macro with odbc from newly created (new one).
    From this newly created i could connect to my current workbook using odbc connection.

    It is possible to move the code from current workbook and run it from newly created?

    Best,
    Jacek

  2. #2
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Run macro from newly created workbook

    Hi,
    May be you can try to save your file with macro as .xlam (Add-on), then apply this Add-on. This way you could run your code from every excel file you open.

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,945

    Re: Run macro from newly created workbook

    Hi kasan.

    I can't do this because workbook is read by java later.

    What is this .xlam file?

    I think that here creating simple temporary copy can be better solution...

    Best,
    Jacek

  4. #4
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Run macro from newly created workbook

    Open your file with macro code, Save As - choose type "Add-on (.xlam)", Open new excel file, then Developer tab - Add-Ins. Choose just saved file (check it).
    Now this macro code will be avaliable in all excel files.
    This can solve our issue when you create new file and close original. Your code still will be avaliable in this newly created file.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Run macro from newly created workbook

    This is how I usually do.
    Use SaveCopyAs to make a copy of the workbook that you are working from and read the data from there.
    e.g
        Dim fn As String
        With CreateObject("Scripting.FileSystemObject")
            fn = ThisWorkbook.Path & "\" & Replace(.GetTempName, ".tmp", "." & .GetExtensionName(ThisWorkbook.Name))
        End With
        ThisWorkbook.SaveCopyAs fn
        'Read from fn
        '
        Kill fn  '<- don't forget to delete the file at the end

  6. #6
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,945

    Re: Run macro from newly created workbook

    thank you Guys,

    i will use savecopy as method.

    Best,
    Jacek

+ 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. bringing 2 sheets (at the end of workbook) to the Same newly created workbook
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-16-2015, 07:10 AM
  2. [SOLVED] Email newly created line in excel workbook
    By klospros in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 11-21-2014, 11:48 AM
  3. Extract data from a newly created workbook with a changing name based on a date.
    By Rigoberto in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-25-2013, 10:02 AM
  4. use existing creation date of workbook with newly created .saveas workbook
    By dwr0211 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-04-2011, 12:42 PM
  5. Using a macro to add code to a newly created workbook.
    By Alagard in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-16-2010, 06:08 PM
  6. Open newly created macro from new workbook
    By stubarso in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-06-2010, 02:30 PM
  7. Saving Workbook in newly created directory
    By sgreni in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-19-2009, 11:42 AM

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