+ Reply to Thread
Results 1 to 5 of 5

pass the value from the open file to vba macro

  1. #1
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    pass the value from the open file to vba macro

    Hi all,

    I found this code that is as some help to me:
    Please Login or Register  to view this content.
    What I need is to pass the value from NewFN to some part in the macro so I can refer to it.
    I need to open a workbook and copy some data from it and then past it in another workbook.

    Part of the solution was to use the Thisworkbook (as this is where the macro is) and ActiveWorkbook for the other workbook that was opened with the above code.
    But if the user has more workbooks open, I would like to avoid that the wrong workbook could be selected.

    Any ideas?

    Greetings.

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: pass the value from the open file to vba macro

    Hi,

    you can use a variable to refer to a specific workbook to avoid "ActiveWorkbook" e.g.
    Please Login or Register  to view this content.
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: pass the value from the open file to vba macro

    Maybe use

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: pass the value from the open file to vba macro

    Hi tehneXus,

    Thanks for the great help.
    Is it also possible to do this with the sheet from the active workbook?
    As the active workbook becomes xlWb, maybe this can also be done on the sheet, so if I would need data from the second sheet that could have a name "Data2".

    This magic of Dim, Set and so on are still so difficult for me to understand. Are there any places/books where I could read and understand it better?

    Thanks and greetings.

  5. #5
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: pass the value from the open file to vba macro

    Quote Originally Posted by Megatronixs View Post
    Is it also possible to do this with the sheet from the active workbook?
    I'd suggest to always indicate the type of variable in the variable name, "Data2" can be everything. This will help you identifying the variable especially when the code gets longer and consist of much more variables. Also start your variable names with a lower case letter, upper case letters are used for functions and subs.
    I am always using the "xl" prefix for excel objects and an abbreviation for the type, e.g. "Ws" = Worksheet and "Wb" = Workbook.
    Also "sh" = Sheet is used a lot.

    Please Login or Register  to view this content.

    You can getting started with VBA with (While reading this please note, avoid using the "Select" function and the "Selection" object where possible):
    Getting started: http://msdn.microsoft.com/en-us/libr...ice.14%29.aspx
    A lot info: http://www.excelforum.com/excel-prog...materials.html
    Very good page: http://www.cpearson.com/Excel/Topic.aspx

+ 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. Can you pass parameters from a batch file to a macro?
    By kimberly_412 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2012, 07:11 PM
  2. [SOLVED] Macro - Master file to import data from another open file with variable file name
    By jdodz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2012, 10:56 PM
  3. macro prompts immediately to open a file once the Excel file with the macro is opened
    By jhmayor03 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2012, 10:00 AM
  4. [SOLVED] Open a file do a macro ( made) and open next succesive file
    By SVTman74 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-21-2006, 05:20 PM
  5. Replies: 0
    Last Post: 02-03-2006, 06:20 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