Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Better way to code Excel automation?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01313820
Message ID:
01313960
Views:
18
>Hi all,
>
>Is there a more maintainable way to code VFP automation of Excel other than "dead reckoning" of cells e.g.
>
>oExcel.ActiveWookBook.ActiveSheet.Range("B5").Value = 100
>
>My client has given me a very complex template to push data across to - I can see coding in hundreds of lines and then them adding a new row half way down the sheet and I have to then go in and increment every cell reference by 1 row.
>
>In Word, I used bookmarks to "tag" a spot in the document and so as long as the bookmark exists, I can find it and insert text. Users can therefore continue to add or change text as long as they leave the bookmarks in.
>
>Does Excel have the ability to "tag" a cell with a name (within the template) so that I can find the cell by name and update it's data?
>
>Albert

I need to read many different Excel files to get new catalog prices for my jobber system. I developed this code so it is very easy to adjust the cells and ranges I need to read.

The procedures lCleanChar() and lCleanNum() simply make sure the data is of the type expected. ie if COL_B is supposed to be numeric but has a chr value it converts it to zero.
HTH
John
#DEFINE COL_A .Columns( 1).Value
#DEFINE COL_B .Columns( 2).Value
#DEFINE COL_C .Columns( 3).Value
#DEFINE COL_D .Columns( 4).Value
#DEFINE COL_E .Columns( 5).Value
#DEFINE COL_F .Columns( 6).Value
#DEFINE COL_G .Columns( 7).Value
#DEFINE COL_H .Columns( 8).Value
#DEFINE COL_I .Columns( 9).Value
#DEFINE COL_J .Columns(10).Value
#DEFINE COL_K .Columns(11).Value
#DEFINE COL_L .Columns(12).Value
#DEFINE COL_M .Columns(13).Value
*
mLastColumn = 300

mRange = 'A' + alltrim(str(mStartRow)) ;
+ ':' ;
+ mLastColumn + alltrim(str(mStartRow))
*
oRange = oSheet1.Range(mRange)
for mRow = mStartRow to mLastRow
  wait window nowait ;
  'Working on Row: '+ alltrim(str(mRow)) + ' of ' + alltrim(str(
  *
  select NewPrices
  scatter memvar blank
  *
  * Read the spreadsheet data
  With oRange
    m.manfptno = lCleanChar(COL_B)
    m.partno   = m.manfptno
    m.manfunit = upper(lCleanChar(COL_C))
    m.descr    = lCleanChar(COL_D)
  EndWithh
endfor
Beer is proof that God loves man, and wants him to be happy. - Benjamin Franklin
John J. Henn
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform