Results 1 to 4 of 4

Thread: [RESOLVED] Define Name in Excel using VB6

  1. #1

    Thread Starter
    Addicted Member Guru's Avatar
    Join Date
    May 2000
    Location
    sulking in the cupboard under the stairs
    Posts
    237

    Resolved [RESOLVED] Define Name in Excel using VB6

    I have a program which writes loads of data to an Excel spreadsheet
    I need to be able to define a name (in Excel it's Insert -> Name -> define from the menus)
    Any ideas how I can do this?
    The program runs as a batch job so sendkeys is not really the way I want to go


    Thanks
    Another light-hearted post from Guru

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Define Name in Excel using VB6

    Assuming you are using Excel automation (eg: objSheet.Cells(x,y) = 1 ) then the easiest way to find out the code you want (for this and most other things) is to do it manually while recording a macro - because the macro contains code that is almost what you should be using.

    There is a section in my Excel tutorial (link in my signature) which explains how to put the macro code into your program properly.

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Define Name in Excel using VB6

    Something like this: (wb is a workbook object)
    Code:
        wb.Names.Add Name:="My_Name", RefersTo:=wb.Worksheets("SheetName").Range("A2:A10")
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4

    Thread Starter
    Addicted Member Guru's Avatar
    Join Date
    May 2000
    Location
    sulking in the cupboard under the stairs
    Posts
    237

    Re: Define Name in Excel using VB6

    Thanks for the replies
    That's great!
    Another light-hearted post from Guru

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