+ Reply to Thread
Results 1 to 6 of 6

Workbook.Names not working

Hybrid View

  1. #1
    Registered User
    Join Date
    01-22-2022
    Location
    Berlin
    MS-Off Ver
    2019
    Posts
    2

    Workbook.Names not working

    Hi Community,

    something strange here, both of these simplest of commands do not work:


    Sub Test()

    ThisWorkbook.Names.Count

    ActiveWorkbook.Names.Add Name:="Test"

    End Sub


    The .Count statement results in "improper use of a property" (actual error message is in German, so I don't know the exact english wording of the error message).

    The .Names.Add results in "application or object defined error".

    Excel 2019, Windows 10, VBA.

    What am I doing wrong?


    Thanks
    Markus

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,213

    Re: Workbook.Names not working

    Try:

    Dim lNameCount As Long
    lNameCount = ThisWorkbook.Names.Count
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,213

    Re: Workbook.Names not working

    https://docs.microsoft.com/en-us/off...workbook.names

    https://docs.microsoft.com/en-us/off...el.names.count

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,937

    Re: Workbook.Names not working

    ActiveWorkbook.Names.Add Name:="Test", RefersToR1C1:= "=Sheet1!R1C1"
    Ben Van Johnson

  5. #5
    Registered User
    Join Date
    01-22-2022
    Location
    Berlin
    MS-Off Ver
    2019
    Posts
    2

    Re: Workbook.Names not working

    Silly me, of course the .count has to have put somewhere.
    I had .refersto but did not think of R1C1
    Thanks, works now.

    But the same in vb.net via ExcelDNA does not work:

    Dim tempRng As Range = SheetEquipment.Cells(2, 2)
    
    Debug.Print(tempRng.Rows.Count)
    Debug.Print(Wb.Names.Count)
    
    Wb.Names.Add(Name:="Test", RefersTo:=tempRng)
    'Wb.Names.Add(Name:="Test", RefersToR1C1:=tempRng)
    'Wb.Names.Add(Name:="Test", RefersToR1C1:="=Equipment!Z2S2")
    'Wb.Names.Add(Name:="Test", RefersToR1C1:="=Equipment!R2C2")
    The counts both work (0 for wb.names.count and 1 for tempRng.Rows.Count) but none of the .Add statements.

    What am I missing?

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,213

    Re: Workbook.Names not working

    Deleted by author.

+ 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. Stop Duplicating Workbook Names as Worksheet Names
    By cbrown6305 in forum Excel General
    Replies: 4
    Last Post: 06-12-2020, 04:59 PM
  2. Open 2nd workbook find matching worksheet names and copy values to 1st workbook
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-09-2017, 10:22 AM
  3. [SOLVED] List in dynamic combobox which shows open workbook names and workshee names
    By igormigor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-01-2016, 06:09 AM
  4. [SOLVED] Copy Values From Each Workbook in Folder to a Single Sheet in New Workbook +Workbook names
    By Arsham24 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-21-2012, 07:42 PM
  5. Changing all excel workbook names in a folder code is not working
    By salventuro in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2009, 11:41 PM
  6. [SOLVED] Using Sheet names & Workbook names in VBA coding
    By Colin Foster in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-07-2006, 02:10 PM
  7. [SOLVED] how do I find names in a workbook full of names
    By aj in forum Excel General
    Replies: 1
    Last Post: 01-19-2006, 05:10 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