Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Excel


Антон1209 ©   (2006-01-23 09:28:00) 

Подскажите как в Excel получить наименование всех именованных областей?


Антон1209   (2006-01-23 16:05:00) [1]

спасибо понял


Digitman   (2006-01-23 15:54:00) [2]

procedure TForm1.Button1Click(Sender: TObject);
var
v_Tmp: OLEvariant;
Xlap, IWorkbook: OLEVariant;
r: integer;
begin
XLap:=CreateOLEObject('Excel.Application');
try
 IWorkbook:=Xlap.workbooks.Open('C:\r_count_mo.xls');
 v_Tmp:=IWorkbook.Names;
 for r:=1 to v_Tmp.Count do
  begin
   ComboBox1.Items.Add(v_Tmp. Item(r).Name);
  end;
finally
  Xlap.Quit;
end;
end;


Антон1209   (2006-01-23 15:23:00) [3]

ошибка в строке

ComboBox1.Items.Add(v_Tmp[r].Name);


Антон1209   (2006-01-23 14:55:00) [4]

---------------------------
Debugger Exception Notification
---------------------------
Project GenRep.exe raised exception class EVariantInvalidArgError with message 'Invalid argument'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------

var
 v_Tmp: variant;
 Xlap, IWorkbook: variant;
 r: integer;
begin
 try
  XLap:=CreateOLEObject('Excel.Application');
  IWorkbook:=Xlap.workbooks.add('C:\GenRep\r_count_mo.xls');
  v_Tmp:=IWorkbook.Names;
  for r:=1 to v_Tmp.Count do
   begin
    ComboBox1.Items.Add(v_Tmp[r].Name);
   end;
 except
  XLap.Quit;
 end;
end;


Digitman   (2006-01-23 10:34:00) [5]

Значит, у тебя ошибка в 17-й строке..


Антон1209   (2006-01-23 10:26:00) [6]

---------------------------
Debugger Exception Notification
---------------------------
Project GenRep.exe raised exception class EOleError with message 'Method 'Name' not supported by automation object'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------


Антон1209   (2006-01-23 09:59:00) [7]

спасибо


Digitman   (2006-01-23 09:40:00) [8]

цитата из станд.справке к ExcelVBA:

Using the Names Collection
Use the Names property to return the Names collection. The following example creates a list of all the names in the active workbook, plus the addresses they refer to.

Set nms = ActiveWorkbook.Names
Set wks = Worksheets(1)
For r = 1 To nms.Count
   wks.Cells(r, 2).Value = nms(r).Name
   wks.Cells(r, 3).Value = nms(r).RefersToRange.Address
Next


Наверх

Титульная страница Поиск, карта сайта Написать письмо