Results 1 to 2 of 2

Thread: Assign an excel open workbook name to a avariable

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Location
    Dist 2, Ho Chi Minh City,Viet Nam
    Posts
    13

    Assign an excel open workbook name to a avariable

    Hi all,

    In a macro in Excel , I open a paticular excel file , for example Tg.xls. Now It's open in a current window.
    How can I assign the name of the file to an avariable, for example n ?
    (So n should equal to a text "tg.xls" after that.)

    Thank you very much for your help.

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    VB Code:
    1. ' After the workbook is opened, it will be the active workbook.
    2.  
    3. ' Name property returns the name.
    4. n = ActiveWorkbook.Name
    5.  
    6. ' FullName returns the full path where the workbook is saved.
    7. n = ActiveWorkbook.FullName
    8.  
    9. ' Workbooks(n) returns the name of a specific open work book.
    10. ' In this case n = 2 so it returns the name of the 2nd open workbook.
    11. n = Workbooks(2).Name

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width