Results 1 to 5 of 5

Trouble setting workbook variable

Threaded View

TC1980 Trouble setting workbook... 08-29-2013, 11:49 AM
Solus Rankin Re: Trouble setting workbook... 08-29-2013, 11:51 AM
TC1980 Re: Trouble setting workbook... 08-29-2013, 11:57 AM
Solus Rankin Re: Trouble setting workbook... 08-29-2013, 12:10 PM
TC1980 Re: Trouble setting workbook... 08-30-2013, 05:52 AM
  1. #1
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Trouble setting workbook variable

    Hi,

    I have two workbooks, one a main Tracker and the other a template that is populated with data then saved. I'm writing the code to reside in the main tracker but reference and manipulate the template as required.
    In order to keep the code tidy and more readable I'm trying to declare a couple of workbook variables and then worksheets variables to act as shorthand when specifying ranges across the two workbooks.

    I can set the variable for the tracker as this uses the Thisworkbook property but I'm getting a 'subscript out of range' error on the template one:

    Dim TrackerWB as workbook, PymtTLWB as workbook
    
    Set TrackerWB = ThisWorkbook 'works
    Set PymtTLWB = Workbooks("PT Template") 'doesn't work
    I'm guessing I somehow have the syntax wrong but can't quite work it out. I've also run the code with just the Tracker open and with both the Tracker and the Template open, but it makes no difference.

    Ideally, I'd like to get the workbook name from a full filepath held in a range using a function I have to get the file name from a file path (this on it's own works fine, but same error when combined with the workbook variable) but I figure one step at a time!

    As always, any help appreciated.

    Thanks, TC
    Last edited by TC1980; 08-29-2013 at 11:52 AM. Reason: Code tags didn't work

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 08-07-2013, 10:16 AM
  2. setting a workbook object using a workbook name that is a variable
    By amazingg64 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-07-2012, 08:23 PM
  3. Trouble Setting a Range
    By CJ944 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-12-2012, 10:53 AM
  4. Trouble Setting a cell to a value
    By jubi23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-18-2007, 02:52 PM
  5. Setting a workbook name as a variable...
    By apeface76 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-27-2005, 03:59 PM

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