Hi, I didn't get yet that far with structures. It should be my next move as I am heading toward c++ and I strongly believe it will help to understand the concept of objects in many languages (it could be Oobasic, coming cloud computing macros and so on and as for now Excel vba). Lots of evening and week-end work but i hope it will make thing easier writing powerfull vba macros in excel and else where i hope.
I just can tell from you code wkb[3].Cells[i,3] ... Cell[i,3] is not a c notation, it would be considered as Cell[i, 3 != NULL] ... i'm not sure actually... About the use of objects, the line where i get stuck is ws = Worksheets; Was Worksheet declared as a variable somewhere before? Anyway, I'm learning a little from this code but it's too early i think. Later, once i get into chained list structures, the code should help. But vba is a specific programming language but maybe it has more to do with c++ than with c. Thanks Regards, On Sep 24, 3:45 pm, Stuart Redmann <[email protected]> wrote: > On 23 Sep., cyber 1000s wrote: > > > > > > > > > > > Hi cyberspace, > > > I have some c programming background... > > Is it possible to increment a worksheet object (worksheets collection) > > in a loop such as below ? > > > Public Sub CopyShNamesFromWkbToWkb2() > > > Dim i As Integer > > Dim wkb As Object > > Set wkb = Workbooks("Nouveau_Feuille_Excel_1.xls") > > Dim wkb2 As Object > > Set wkb2 = Workbooks("Classeur1.xls") > > Dim ws As Object > > Set ws = Worksheets > > > For i = 1 To ws.Count > > wkb.Sheets(3).Cells(i, 4) = wkb2.ws(i).Name '///A > > Next i > > > End Sub > > > line ///A should be: wkb.Sheets(3).Cells(i, 4) = > > wkb2.Sheets(i).Name > > > Why a property pointing on an object variable such as count is working > > but not if it's being incremented like any excel vba name : > > sheets(i)... and not ws affected as a sheet ? > > Since you have experience with C, let's transpose your VBA question > into a C question: > > /* The following definitions simulate the Excel run-time. > */ > typedef struct > { > char* Name; > > } Worksheet; > > typedef struct > { > Worksheet* Sheets; > > } Workbook; > > workbook* Workbooks; /* Global Workbooks collection */ > Worksheet* Worksheets; /* Global Worksheets collection */ > > /* Here comes your code. > */ > void CopyShNamesFromWKbToWkb2 () > { > int i; > Workbook* wkb; /* = Nouveau_Feuille_Excel_1.xls */ > Workbook* wkb2; > Worksheet* ws; > ws = Worksheets; > > for (i = 0; i < Count(ws); ++i) > wkb[3].Cells[i,3] = wkb2.ws[i].Name > > } > > Can you spot your mistake now? > > Regards, > Stuart -- ---------------------------------------------------------------------------------- Some important links for excel users: 1. Follow us on TWITTER for tips tricks and links : http://twitter.com/exceldailytip 2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310 3. Excel tutorials at http://www.excel-macros.blogspot.com 4. Learn VBA Macros at http://www.quickvba.blogspot.com 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com To post to this group, send email to [email protected] <><><><><><><><><><><><><><><><><><><><><><> Like our page on facebook , Just follow below link http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts
