Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel VBA PEM to get/set column FORMAT
Message
De
03/12/2005 12:30:25
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
03/12/2005 12:05:13
Information générale
Forum:
Visual FoxPro
Catégorie:
Produits tierce partie
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01074459
Message ID:
01074607
Vues:
23
Jim,
Sorry couldn't resist again.
"And, of course, as I insert columns the column IDs ("AA", "DT", etc) change.
>So I start my work from the right side, so that my reference columns remain with the same col#."
AA, DT changing shouldn't be a concern. Once you mark the region (range like range("myDataIsland")) AA,DT loses importance. You can use relative ranges like:
.Range("myDataIsland").Columns(1) && 1st column of myDataIsland
.Range("myDataIsland").Rows(2)
.Range("myDataIsland").Columns(1).Rows(4) && same as .Range("myDataIsland").Cells(4,1)

* same size of the island starting 2 rows below and 2 cols right - like cascaded window
.Range("myDataIsland").Offset(2,2).Select 

* A3 is col1,row3 within dataisland. Go 1 row above and 2 columns left and change font color
.Range("myDataIsland").Range("A3").Offset(-1,-2).Font.Color = 0x255

.Range("myDataIsland").Cells(3,2).Select && row3,col2 within island
.Range("myDataIsland").Range("B2:D10").Select && col2, row2 to col4,row10 within island
etc.
Cetin

>I don't know the columns from run-to-run. The data can come from anywhere and contain anything and I want to get it into a dbf so I can do more work on the data. The data has lots of "comments" types of fields, randomly, and I want to make sure that I do not lose ANY of the long comment information. Some of the comments take 5 fields defined as 254 characters to hold all of it. I also, for ease later, want to keep the extra columns inserted adjacent to the 'source' column. And, of course, as I insert columns the column IDs ("AA", "DT", etc) change.
>So I start my work from the right side, so that my reference columns remain with the same col#.
>
>Now I do see that I could essentially do the work to a new sheet in the same workbook, and I think I will give that a go.
>
>No pain, Cetin < s >
>
>
>>I warned you I could be a pain in the neck:)
>>This way or that way you know those columns from run-to-run. Since you know xx to add 1 to it I assume you do. OK this is the last one and I would let you go:) More than needed variables here for some clarity what it's doing (note that it intentionally includes a memo as I remember you said dividing memo into columns and later deal with).
>>
>>Select emp_id,First_Name,Last_Name,Title,Notes ;
>>    from (Home()+'samples\data\employee') ;
>>    into Cursor crsToExcel ;
>>    nofilter
>>
>>oExcel = Createobject("Excel.Application")
>>With oExcel
>>    .Workbooks.Add
>>    .Visible = .T.
>>    With .ActiveWorkBook.ActiveSheet
>>        .Range('A1:F7000').Cells.Value = 'filled'
>>        lnStartColumn = 3 && this is xx+1
>>        lnColumns = Fcount()
>>        lcColStart = _GetChar(m.lnStartColumn) && Get Excel column name
>>        lcColEnd = _GetChar(m.lnStartColumn+m.lnColumns-1)
>>        lnRowEnd = Reccount()+1
>>        lcDataRange = Textmerge('<<m.lcColStart>>1:<<m.lcColEnd>><<m.lnRowEnd>>')
>>        .Range(Textmerge('<<m.lcColStart>>:<<m.lcColEnd>>')).EntireColumn.Insert
>>        .Range(m.lcDataRange).Name = "myDataIsland"
>>        VFP2Excel(oExcel, 'crsToExcel', .Name, "myDataIsland") && Insert data there
>>    Endwith
>>Endwith
>>
>>* Return A, AA, BC etc noation for nth column
>>Function _GetChar
>>Lparameters tnColumn && Convert tnvalue to Excel alpha notation
>>If tnColumn = 0
>>    Return ""
>>Endif
>>If tnColumn <= 26
>>    Return Chr(Asc("A")-1+tnColumn)
>>Else
>>    Return 	_GetChar(Int(Iif(tnColumn % 26 = 0,tnColumn - 1, tnColumn) / 26)) + ;
>>        _GetChar((tnColumn-1)%26+1)
>>Endif
>>
>>Function VFP2Excel
>>Lparameters toExcel, tcCursorName, tcSheetName, tcRange
>>tcCursorName = Iif(Empty(m.tcCursorName),Alias(),m.tcCursorName)
>>tcSheetName = Iif(Empty(m.tcSheetName),"Sheet1", m.tcSheetName)
>>Local loConn As AdoDB.Connection, loRS As AdoDB.Recordset,;
>>    lcTempRs, lcTemp, oExcel
>>lcTemp = Forcepath(Sys(2015)+'.dbf',Sys(2023))
>>lcTempRs = Forcepath(Sys(2015)+'.rst',Sys(2023))
>>Select (m.tcCursorName)
>>Copy To (m.lcTemp)
>>loConn = Createobject("Adodb.connection")
>>loConn.ConnectionString = "Provider=VFPOLEDB;Data Source="+Sys(2023)
>>loConn.Open()
>>loRS = loConn.Execute("select * from "+m.lcTemp)
>>loRS.Save(m.lcTempRs)
>>loRS.Close
>>loConn.Close
>>Erase (m.lcTemp)
>>loRS.Open(m.lcTempRs)
>>
>>With toExcel.WorkSheets( ;
>>        Iif(Empty(m.tcSheetName),;
>>        .ActiveWorkBook.ActiveSheet.Name, ;
>>        m.tcSheetName))
>>    .QueryTables.Add( loRS, .Range(m.tcRange)).Refresh()
>>    .Range(m.tcRange).AutoFormat(8) && xlRangeAutoFormatColor2
>>    .Range("A1").Activate
>>Endwith
>>loRS.Close
>>Erase (m.lcTempRs)
>>
>>PS:ADO part is based on FoxyClasses' dbf2excel class.
>>Cetin
>>
>>
>>>My first problem was that I could not name a range by "A:A" format, because I did not know which columns were involved from run-to-run.
>>>TamarG came up with
            Set oRange = oSheet.Columns(xx + 1)
>>>oRange.Insert (xlShiftToRight)
, which did the job nicely compared to cell-by-cell.
>>>cheers, and thanks for the hints
Ç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
Répondre
Fil
Voir

Click here to load this message in the networking platform