+ Reply to Thread
Results 1 to 8 of 8

problem opening workbook and assigning variable

  1. #1
    Forum Contributor
    Join Date
    09-12-2013
    Location
    chicago, illinois
    MS-Off Ver
    Excel 2010
    Posts
    109

    problem opening workbook and assigning variable

    good day all. i am trying to open a workbook, assign it a variable and use that variable later. here is what i have

    Please Login or Register  to view this content.
    when i try to activate it later on in another procedure using:
    Please Login or Register  to view this content.
    i receive an "Automation Error"

    i have tried declaring it as a public variable, even a global variable and cannot get this to work.

    all i'm really wanting to do is open a workbook (where the name will change depending on the book being opened), assign that workbook a variable name, and use it later in the code.

    thanks!

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: problem opening workbook and assigning variable

    Hi,

    Try defining it as a global variable in an ordinary code module such as Module1:
    Please Login or Register  to view this content.
    Lewis

  3. #3
    Forum Contributor
    Join Date
    09-12-2013
    Location
    chicago, illinois
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: problem opening workbook and assigning variable

    thanks lewis, but i've tried that already :-/ i try to use something like this:
    Please Login or Register  to view this content.
    and i get that automation error again.

    i have NO idea what i'm doing wrong. i will try to find a way around it after my headache goes away =)

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: problem opening workbook and assigning variable

    Why are you opening the workbook twice?

    This should open a workbook and create a variable that references it.
    Please Login or Register  to view this content.
    Once you have the variable referencing there's no need to activate the workbook, though it will automatically be the active workbook when you open it.
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    09-12-2013
    Location
    chicago, illinois
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: problem opening workbook and assigning variable

    i'm sorry, i was just using that as an example...a better one would be the problem i'm running into now:

    on a userform i have a button that does a few things, one is it assigns the value in cell D4 to a variable: dtest2

    i have this code:

    Please Login or Register  to view this content.
    and thats where i'm getting my Automation error upon clicking the button.

    edit** oh, and sorry Norie, yeah, i noticed that too, i deleted the 2nd line of code there opening the document twice....AND that definately fixed the problem *sigh* lol thanks!!!!
    Last edited by fredderf81; 07-14-2014 at 01:37 PM.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    So this is solved?

  7. #7
    Forum Contributor
    Join Date
    09-12-2013
    Location
    chicago, illinois
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: problem opening workbook and assigning variable

    i'm sorry!!! i usually close them...must have timed out the window. i will take care of it

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: problem opening workbook and assigning variable

    fredder

    I just wasn't sure if you had found a solution.

+ 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. [SOLVED] Opening Workbook With Variable Name
    By mattman123 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-19-2014, 05:21 PM
  2. Need help assigning variable from a range in another workbook
    By impactrx8 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2013, 11:17 PM
  3. Assigning Specific Cell on opening of workbook
    By Johnmus in forum Excel General
    Replies: 2
    Last Post: 06-07-2012, 06:15 AM
  4. Opening and Assigning a Logical Name to a Workbook using VBA
    By EddieN1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2012, 11:36 AM
  5. Assigning variable to open workbook
    By DavidBW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-21-2011, 06:04 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