+ Reply to Thread
Results 1 to 2 of 2

How can I know which one is workbooks(1) or (2) etc

  1. #1
    Forum Contributor
    Join Date
    04-09-2013
    Location
    City, World
    MS-Off Ver
    Office 365
    Posts
    248

    How can I know which one is workbooks(1) or (2) etc

    Hi
    I have 3 files are opned. The one I am working on is called Book1 (default name did not change it or saved it yet). Then using Worksheets.add I added Book2 and then using Worksheet.add.saveas, I added 1.xlsx

    Now after this running the code below
    Please Login or Register  to view this content.
    1.xlsx is the one which is protected now. My question how do I know 1.xlsx is workbooks(3). Lets say I created 10 workbooks and named them different, how can I know which one is workbooks(1) or workbooks(2) etc. If I want to use workbooks() in my code?

    Also please if you do not mind. I know a workbook with name hello.xlsx can be refer in VBA as this

    workbooks(1)
    workbooks("hello.xlsx")

    what else I can use to refer to the first workbook. I am trying to compare that with sheet. In sheets we can refer to the first sheet as this

    Sheet1
    Worksheets(1)
    Worksheets("hello")

    Thank you very much.
    Last edited by lastnn30; 02-25-2021 at 12:10 AM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: How can I know which one is workbooks(1) or (2) etc

    Hey lastnn,

    Perhaps you could use something like:
    If Workbooks(1).Name = "Data1" then

    you could tell which was which index number.
    https://docs.microsoft.com/en-us/off...Excel.Workbook
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ 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] Trying to refer to Workbook in VBA, when workbook name is the combination of cells
    By vagofone in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2016, 06:14 PM
  2. Refer to another workbook by name in a cell
    By matteobsuetti in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-01-2015, 10:03 AM
  3. Refer to a particular workbook
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-06-2015, 07:20 AM
  4. [SOLVED] How to refer to the workbook where the macro when another workbook is open during runtime?
    By jonelamora in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-04-2012, 11:21 PM
  5. how to refer to new workbook
    By aretai in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-06-2010, 07:26 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