[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
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.
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")
Re: Define Name in Excel using VB6
Thanks for the replies
That's great!