Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel COM automation - bookmarks and quick searches
Message
De
05/09/2000 07:16:28
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
04/09/2000 12:44:06
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00412211
Message ID:
00412386
Vues:
13
>>>I am wondering if there is a way to have a VFP application through COM open an excel sheet and quickly identify certain cells. I don't want to go through the entire sheet cell by cell looking for what I need. I could try to do a find, but I wonder if there is a better way. In word I could create bookmarks, but I don't see that in excel.
>>>
>>>Cesar
>>
>>In Excel you can apply a "name" to one, or a range of, cells. Will this give you what you need?
>
>Yes, it might, can you then search for that name and it will give you the cell location?


Hi Cesar,
Name is like bookmarks in word in a way. First of all keep in mind that a name 'RefersTo' a range not to only a cell (might be). A range might be a cell, a group of cells or even union of different group of cells. 'Name' refersto all that range and could directly be used in formulas (ie: =sum(myName)).
To test the code create a test workbook with different name definitions (visible = .t. at first line slows down but I wanted to show what's going on):
lparameters tcXlsFullPath
oExcel = createobject('Excel.Application')
WITH oExcel
  .visible = .t.
  .Workbooks.Open(tcXlsFullPath)
  WITH .Activeworkbook
    .WorkSheets.Add
    WITH .ActiveSheet
      .Name = 'Bookmarks'
      FOR ix=1 to oExcel.Activeworkbook.Names.Count
        .Cells(ix, 1).Value = oExcel.Activeworkbook.Names(ix).Name
        .Cells(ix, 2).Value = "'" + oExcel.Activeworkbook.Names(ix).RefersTo
      ENDFOR
      .Columns("A:B").AutoFit
      WAIT timeout 3
      FOR ix=1 to oExcel.Activeworkbook.Names.Count
        lcRefers = oExcel.Activeworkbook.Names(ix).RefersTo
        lcSheet = substr(lcRefers,2,at('!',lcRefers)-2)
        lcAddress = chrtran(substr(lcRefers,at('!',lcRefers)+1),'$','')
        oExcel.Activeworkbook.Sheets(lcSheet).Activate
        oExcel.Activeworkbook.ActiveSheet.Range(lcAddress).Select
        WAIT timeout 2
      ENDFOR
    ENDWITH
  ENDWITH
ENDWITH
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform